Skip to content

Commit

Permalink
feat: add hiddenAliases to Command
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Apr 8, 2024
1 parent c992403 commit f87fbdb
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@oclif/core",
"description": "base library for oclif CLIs",
"version": "2.15.0",
"version": "2.16.0",
"author": "Salesforce",
"bugs": "https://github.com/oclif/core/issues",
"dependencies": {
Expand Down
4 changes: 4 additions & 0 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ export abstract class Command {
/** Hide the command from help */
public static hidden: boolean

/** An array of aliases for this command that are hidden from help. */
public static hiddenAliases: string[]

/** Mark the command as a given state (e.g. beta or deprecated) in help */
public static state?: 'beta' | 'deprecated' | string;

Expand Down Expand Up @@ -418,6 +421,7 @@ export namespace Command {
[key: string]: unknown;
id: string;
hidden: boolean;
hiddenAliases: string[];
state?: 'beta' | 'deprecated' | string;
deprecationOptions?: Deprecation;
aliases: string[];
Expand Down
15 changes: 15 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,20 @@ export class Config implements IConfig {
this.commandPermutations.add(permutation, command.id)
}
}

for (const alias of command.hiddenAliases ?? []) {
if (this._commands.has(alias)) {
const prioritizedCommand = this.determinePriority([this._commands.get(alias)!, command])
this._commands.set(alias, {...prioritizedCommand, id: alias})
} else {
this._commands.set(alias, {...command, id: alias})
}

const aliasPermutations = this.flexibleTaxonomy ? getCommandIdPermutations(alias) : [alias]
for (const permutation of aliasPermutations) {
this.commandPermutations.add(permutation, command.id)
}
}
}

marker?.addDetails({commandCount: plugin.commands.length})
Expand Down Expand Up @@ -915,6 +929,7 @@ export async function toCached(c: Command.Class, plugin?: IPlugin | undefined, i
hidden: c.hidden,
state: c.state,
aliases: c.aliases || [],
hiddenAliases: c.hiddenAliases || [],
examples: c.examples || (c as any).example,
deprecationOptions: c.deprecationOptions,
deprecateAliases: c.deprecateAliases,
Expand Down
1 change: 1 addition & 0 deletions test/command/command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ describe('command', () => {
id: 'foo:bar',
type: 'mytype',
hidden: true,
hiddenAliases: [],
pluginName: undefined,
pluginAlias: undefined,
pluginType: undefined,
Expand Down
2 changes: 2 additions & 0 deletions test/config/config.flexible.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('Config with flexible taxonomy', () => {
flagA: Flags.boolean({char: 'a'}),
},
hidden: false,
hiddenAliases: [],
id: commandIds[0],
async load(): Promise<Command.Class> {
return MyCommandClass
Expand All @@ -75,6 +76,7 @@ describe('Config with flexible taxonomy', () => {
flagB: Flags.boolean({}),
},
hidden: false,
hiddenAliases: [],
id: commandIds[1],
async load(): Promise<Command.Class> {
return MyCommandClass
Expand Down
2 changes: 2 additions & 0 deletions test/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ describe('Config', () => {
aliases: [], args: {}, flags: {}, hidden: false, id: commandIds[0], async load(): Promise<Command.Class> {
return MyCommandClass
},
hiddenAliases: [],
pluginType: types[0] ?? 'core',
pluginAlias: '@My/plugina',
}
Expand All @@ -263,6 +264,7 @@ describe('Config', () => {
aliases: [], args: {}, flags: {}, hidden: false, id: commandIds[1], async load(): Promise<Command.Class> {
return MyCommandClass
},
hiddenAliases: [],
pluginType: types[1] ?? 'core',
pluginAlias: '@My/pluginb',
}
Expand Down

0 comments on commit f87fbdb

Please sign in to comment.