@clerc/plugin-help 0.41.0 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +21 -21
  2. package/dist/index.js +38 -28
  3. package/package.json +5 -5
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Ray <https://github.com/so1ve>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Ray <https://github.com/so1ve>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.js CHANGED
@@ -55,8 +55,8 @@ const primitiveMap = /* @__PURE__ */ new Map([
55
55
  [Number, "number"]
56
56
  ]);
57
57
  function stringifyType(type, hasDefault = false) {
58
- const res = primitiveMap.has(type) ? primitiveMap.get(type) : "value";
59
- return res ? hasDefault ? `[${res}]` : `<${res}>` : "";
58
+ const result = primitiveMap.has(type) ? primitiveMap.get(type) : "value";
59
+ return result ? hasDefault ? `[${result}]` : `<${result}>` : "";
60
60
  }
61
61
  function sortName(a, b) {
62
62
  if (a === Root) {
@@ -161,8 +161,8 @@ const defaultRenderers = {
161
161
  renderDefault: JSON.stringify
162
162
  };
163
163
 
164
- function generateHelp(render2, ctx, notes, examples, _renderers) {
165
- const { cli } = ctx;
164
+ function generateHelp(render2, context, notes, examples, _renderers) {
165
+ const { cli } = context;
166
166
  const { t } = cli.i18n;
167
167
  let sections = [];
168
168
  const renderers = Object.assign(
@@ -177,13 +177,13 @@ function generateHelp(render2, ctx, notes, examples, _renderers) {
177
177
  yc.magenta(
178
178
  `$ ${cli._scriptName} ${withBrackets(
179
179
  "command",
180
- ctx.hasRootOrAlias
180
+ context.hasRootOrAlias
181
181
  )} [flags]`
182
182
  )
183
183
  ]
184
184
  });
185
185
  const commands = [
186
- ...ctx.hasRoot ? [cli._commands[Root]] : [],
186
+ ...context.hasRoot ? [cli._commands[Root]] : [],
187
187
  ...Object.values(cli._commands)
188
188
  ].map((command) => {
189
189
  var _a;
@@ -220,9 +220,9 @@ function generateHelp(render2, ctx, notes, examples, _renderers) {
220
220
  sections = renderers.renderSections(sections);
221
221
  return render2(sections);
222
222
  }
223
- function generateSubcommandHelp(render2, ctx, command) {
223
+ function generateSubcommandHelp(render2, context, command) {
224
224
  var _a, _b, _c, _d, _e, _f;
225
- const { cli } = ctx;
225
+ const { cli } = context;
226
226
  const { t } = cli.i18n;
227
227
  const [subcommand] = resolveCommandStrict(cli._commands, command, t);
228
228
  if (!subcommand) {
@@ -314,13 +314,19 @@ const helpPlugin = ({
314
314
  ]
315
315
  ]
316
316
  }
317
- }).on("help", (ctx) => {
318
- if (ctx.parameters.command.length > 0) {
317
+ }).on("help", (context) => {
318
+ if (context.parameters.command.length > 0) {
319
319
  printHelp(
320
- generateSubcommandHelp(render, ctx, ctx.parameters.command)
320
+ generateSubcommandHelp(
321
+ render,
322
+ context,
323
+ context.parameters.command
324
+ )
321
325
  );
322
326
  } else {
323
- printHelp(generateHelp(render, ctx, notes, examples, renderers));
327
+ printHelp(
328
+ generateHelp(render, context, notes, examples, renderers)
329
+ );
324
330
  }
325
331
  });
326
332
  }
@@ -331,34 +337,38 @@ const helpPlugin = ({
331
337
  default: false
332
338
  });
333
339
  }
334
- cli.inspector((ctx, next) => {
335
- const shouldShowHelp = ctx.flags.help;
336
- if (!ctx.hasRootOrAlias && ctx.raw._.length === 0 && showHelpWhenNoCommand && !shouldShowHelp) {
337
- let str = `${t("core.noCommandGiven")}
340
+ cli.inspector((context, next) => {
341
+ const shouldShowHelp = context.flags.help;
342
+ if (!context.hasRootOrAlias && context.raw._.length === 0 && showHelpWhenNoCommand && !shouldShowHelp) {
343
+ let string_ = `${t("core.noCommandGiven")}
338
344
 
339
345
  `;
340
- str += generateHelp(render, ctx, notes, examples, renderers);
341
- str += "\n";
342
- printHelp(str);
346
+ string_ += generateHelp(render, context, notes, examples, renderers);
347
+ string_ += "\n";
348
+ printHelp(string_);
343
349
  process.exit(1);
344
350
  } else if (shouldShowHelp) {
345
- if (ctx.raw._.length > 0) {
346
- if (ctx.called === Root) {
347
- printHelp(generateSubcommandHelp(render, ctx, ctx.raw._));
351
+ if (context.raw._.length > 0) {
352
+ if (context.called === Root) {
353
+ printHelp(generateSubcommandHelp(render, context, context.raw._));
348
354
  } else {
349
- if (ctx.name === Root) {
355
+ if (context.name === Root) {
350
356
  printHelp(
351
- generateHelp(render, ctx, notes, examples, renderers)
357
+ generateHelp(render, context, notes, examples, renderers)
352
358
  );
353
359
  } else {
354
- printHelp(generateSubcommandHelp(render, ctx, ctx.raw._));
360
+ printHelp(
361
+ generateSubcommandHelp(render, context, context.raw._)
362
+ );
355
363
  }
356
364
  }
357
365
  } else {
358
- if (ctx.hasRootOrAlias) {
359
- printHelp(generateSubcommandHelp(render, ctx, Root));
366
+ if (context.hasRootOrAlias) {
367
+ printHelp(generateSubcommandHelp(render, context, Root));
360
368
  } else {
361
- printHelp(generateHelp(render, ctx, notes, examples, renderers));
369
+ printHelp(
370
+ generateHelp(render, context, notes, examples, renderers)
371
+ );
362
372
  }
363
373
  }
364
374
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/plugin-help",
3
- "version": "0.41.0",
3
+ "version": "0.42.0",
4
4
  "author": "Ray <i@mk1.io> (https://github.com/so1ve)",
5
5
  "type": "module",
6
6
  "description": "Clerc plugin help",
@@ -13,14 +13,14 @@
13
13
  "cli",
14
14
  "terminal"
15
15
  ],
16
- "homepage": "https://github.com/so1ve/clerc/tree/main/packages/plugin-help#readme",
16
+ "homepage": "https://github.com/clercjs/clerc/tree/main/packages/plugin-help#readme",
17
17
  "repository": {
18
18
  "type": "git",
19
- "url": "git+https://github.com/so1ve/clerc.git",
19
+ "url": "git+https://github.com/clercjs/clerc.git",
20
20
  "directory": "/"
21
21
  },
22
22
  "bugs": {
23
- "url": "https://github.com/so1ve/clerc/issues"
23
+ "url": "https://github.com/clercjs/clerc/issues"
24
24
  },
25
25
  "license": "MIT",
26
26
  "sideEffects": false,
@@ -52,7 +52,7 @@
52
52
  "string-width": "^6.1.0",
53
53
  "text-table": "^0.2.0",
54
54
  "yoctocolors": "^1.0.0",
55
- "@clerc/utils": "0.41.0"
55
+ "@clerc/utils": "0.42.0"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "@clerc/core": "*"