Skip to content

Commit

Permalink
fix: deprecated aliases bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Sep 30, 2024
1 parent cc8366a commit 9f07cc3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ export abstract class Command {
// Since config.runHook will only run the hook for the root plugin, hookResult.successes will always have a length of 0 or 1
// But to be extra safe, we find the result that matches the root plugin.
const argvToParse = hookResult.successes?.length
? hookResult.successes.find((s) => s.plugin.root === Cache.getInstance().get('rootPlugin')?.root)?.result ?? argv
? (hookResult.successes.find((s) => s.plugin.root === Cache.getInstance().get('rootPlugin')?.root)?.result ??
argv)
: argv
this.argv = [...argvToParse]
const results = await Parser.parse<F, B, A>(argvToParse, opts)
Expand Down Expand Up @@ -336,7 +337,7 @@ export abstract class Command {
)
if (aliases.length === 0) return

const foundAliases = aliases.filter((alias) => this.argv.some((a) => a.startsWith(alias)))
const foundAliases = aliases.filter((alias) => this.argv.includes(alias))
for (const alias of foundAliases) {
let preferredUsage = `--${flagDef?.name}`
if (flagDef?.char) {
Expand Down
7 changes: 6 additions & 1 deletion test/command/command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('command', () => {
class CMD extends Command {
static flags = {
name: Flags.string({
aliases: ['username', 'target-user', 'u'],
aliases: ['username', 'target-user', 'u', 'nam'],
deprecateAliases: true,
char: 'o',
}),
Expand Down Expand Up @@ -137,6 +137,11 @@ describe('command', () => {
const {stderr} = await captureOutput(async () => CMD.run(['--name', 'u']))
expect(stderr).to.be.empty
})

it('shows no warning when using flag with deprecated alias that starts with the actual flag', async () => {
const {stderr} = await captureOutput(async () => CMD.run(['--name', 'astro']))
expect(stderr).to.be.empty
})
})

describe('deprecated flags', () => {
Expand Down

0 comments on commit 9f07cc3

Please sign in to comment.