@oclif/core 3.0.9 → 3.1.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.
package/lib/command.d.ts CHANGED
@@ -49,6 +49,8 @@ export declare abstract class Command {
49
49
  static help: string | undefined;
50
50
  /** Hide the command from help */
51
51
  static hidden: boolean;
52
+ /** An array of aliases for this command that are hidden from help. */
53
+ static hiddenAliases: string[];
52
54
  /** A command ID, used mostly in error or verbose reporting. */
53
55
  static id: string;
54
56
  static plugin: Plugin | undefined;
@@ -155,6 +157,7 @@ export declare namespace Command {
155
157
  };
156
158
  hasDynamicHelp?: boolean;
157
159
  hidden: boolean;
160
+ hiddenAliases: string[];
158
161
  id: string;
159
162
  isESM?: boolean;
160
163
  permutations?: string[];
package/lib/command.js CHANGED
@@ -94,6 +94,8 @@ class Command {
94
94
  static help;
95
95
  /** Hide the command from help */
96
96
  static hidden;
97
+ /** An array of aliases for this command that are hidden from help. */
98
+ static hiddenAliases = [];
97
99
  /** A command ID, used mostly in error or verbose reporting. */
98
100
  static id;
99
101
  static plugin;
@@ -704,14 +704,13 @@ class Config {
704
704
  for (const permutation of permutations) {
705
705
  this.commandPermutations.add(permutation, command.id);
706
706
  }
707
- // set command aliases
708
- for (const alias of command.aliases ?? []) {
707
+ const handleAlias = (alias, hidden = false) => {
709
708
  if (this._commands.has(alias)) {
710
709
  const prioritizedCommand = this.determinePriority([this._commands.get(alias), command]);
711
710
  this._commands.set(alias, { ...prioritizedCommand, id: alias });
712
711
  }
713
712
  else {
714
- this._commands.set(alias, { ...command, id: alias });
713
+ this._commands.set(alias, { ...command, hidden, id: alias });
715
714
  }
716
715
  // set every permutation of the aliases
717
716
  // v3 moved command alias permutations to the manifest, but some plugins may not have
@@ -723,6 +722,14 @@ class Config {
723
722
  for (const permutation of aliasPermutations) {
724
723
  this.commandPermutations.add(permutation, command.id);
725
724
  }
725
+ };
726
+ // set command aliases
727
+ for (const alias of command.aliases ?? []) {
728
+ handleAlias(alias);
729
+ }
730
+ // set hidden command aliases
731
+ for (const alias of command.hiddenAliases ?? []) {
732
+ handleAlias(alias, true);
726
733
  }
727
734
  }
728
735
  marker?.addDetails({ commandCount: plugin.commands.length });
package/lib/flags.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.option = exports.help = exports.version = exports.string = exports.url = exports.file = exports.directory = exports.integer = exports.boolean = exports.custom = void 0;
4
- /* eslint-disable valid-jsdoc */
5
4
  const node_url_1 = require("node:url");
6
5
  const errors_1 = require("./errors");
7
6
  const help_1 = require("./help");
@@ -98,7 +97,7 @@ const help = (opts = {}) => boolean({
98
97
  ...opts,
99
98
  async parse(_, cmd) {
100
99
  const Help = await (0, help_1.loadHelpClass)(cmd.config);
101
- await new Help(cmd.config, cmd.config.pjson.helpOptions).showHelp(cmd.id ? [cmd.id, ...cmd.argv] : cmd.argv);
100
+ await new Help(cmd.config, cmd.config.pjson.oclif.helpOptions ?? cmd.config.pjson.helpOptions).showHelp(cmd.id ? [cmd.id, ...cmd.argv] : cmd.argv);
102
101
  cmd.exit(0);
103
102
  },
104
103
  });
package/lib/help/index.js CHANGED
@@ -82,7 +82,9 @@ class Help extends HelpBase {
82
82
  formatCommands(commands) {
83
83
  if (commands.length === 0)
84
84
  return '';
85
- const body = this.renderList(commands.map((c) => {
85
+ const body = this.renderList(commands
86
+ .filter((c) => (this.opts.hideAliasesFromRoot ? !c.aliases?.includes(c.id) : true))
87
+ .map((c) => {
86
88
  if (this.config.topicSeparator !== ':')
87
89
  c.id = c.id.replaceAll(':', this.config.topicSeparator);
88
90
  return [c.id, this.summary(c)];
@@ -4,6 +4,10 @@ export interface HelpOptions {
4
4
  * Use docopts as the usage. Defaults to true.
5
5
  */
6
6
  docopts?: boolean;
7
+ /**
8
+ * If true, hide command aliases from the root help output. Defaults to false.
9
+ */
10
+ hideAliasesFromRoot?: boolean;
7
11
  /**
8
12
  * By default, the command summary is show at the top of the help and as the first line in
9
13
  * the command description. Repeating the summary in the command description improves readability
package/lib/main.js CHANGED
@@ -64,7 +64,7 @@ async function run(argv, options) {
64
64
  // display help version if applicable
65
65
  if ((0, exports.helpAddition)(argv, config)) {
66
66
  const Help = await (0, help_1.loadHelpClass)(config);
67
- const help = new Help(config, config.pjson.helpOptions);
67
+ const help = new Help(config, config.pjson.oclif.helpOptions ?? config.pjson.helpOptions);
68
68
  await help.showHelp(argv);
69
69
  await collectPerf();
70
70
  return;
@@ -75,15 +75,17 @@ async function cacheCommand(uncachedCmd, plugin, respectNoCacheDefault = false)
75
75
  const flags = await cacheFlags((0, aggregate_flags_1.aggregateFlags)(uncachedFlags, uncachedBaseFlags, cmd.enableJsonFlag), respectNoCacheDefault);
76
76
  const args = await cacheArgs((0, ensure_arg_object_1.ensureArgObject)(cmd.args), respectNoCacheDefault);
77
77
  const stdProperties = {
78
- aliases: cmd.aliases || [],
78
+ aliases: cmd.aliases ?? [],
79
79
  args,
80
80
  deprecateAliases: cmd.deprecateAliases,
81
81
  deprecationOptions: cmd.deprecationOptions,
82
82
  description: cmd.description,
83
- examples: cmd.examples || cmd.example,
83
+ // Support both `examples` and `example` for backwards compatibility.
84
+ examples: cmd.examples ?? cmd.example,
84
85
  flags,
85
86
  hasDynamicHelp: Object.values(flags).some((f) => f.hasDynamicHelp),
86
87
  hidden: cmd.hidden,
88
+ hiddenAliases: cmd.hiddenAliases ?? [],
87
89
  id: cmd.id,
88
90
  pluginAlias: plugin && plugin.alias,
89
91
  pluginName: plugin && plugin.name,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oclif/core",
3
3
  "description": "base library for oclif CLIs",
4
- "version": "3.0.9",
4
+ "version": "3.1.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {