New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: warn about alias deprecations #540
Conversation
src/command.ts
Outdated
|
||
const deprecateAliases = this.ctor.flags[flag]?.deprecateAliases | ||
const aliases = this.ctor.flags[flag]?.aliases ?? [] | ||
if (deprecateAliases && aliases) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aliases
will always be true since it's ?? []
(empty arrays are truthy).
Did you maybe want aliases.length?
src/command.ts
Outdated
const deprecateAliases = this.ctor.flags[flag]?.deprecateAliases | ||
const aliases = this.ctor.flags[flag]?.aliases ?? [] | ||
if (deprecateAliases && aliases) { | ||
const foundAliases = this.argv.filter(a => aliases.includes(a.replace(/-/g, ''))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's happening with the -
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
argv has the --
/-
on all the flag names e.g., ['--foo', '--bar', '-b']
But the flag aliases don't have the prefix, e.g. ['foo', 'bar', 'b']
So in order to find the intersection, we have to remove all the -
s first
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens for target-org
and no-prompt
and the like?
src/flags.ts
Outdated
@@ -37,7 +37,7 @@ export const help = (opts: Partial<BooleanFlag<boolean>> = {}) => { | |||
description: 'Show CLI help.', | |||
...opts, | |||
parse: async (_: any, cmd: Command) => { | |||
new Help(cmd.config).showHelp(cmd.argv) | |||
new Help(cmd.config).showHelp([cmd.id!, ...cmd.argv]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it matters or not, but I have seen scenarios where a command doesn't have an ID, particularly when we do weird things with them in UT.
One of those "I'm super cautious about asserting things to TS"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested with various hyphenated combos of deprecated aliases.
deprecateAliases
toCommand
- allowing you to emit warnings anytime a command alias is useddeprecateAliases
to all flags - allowing you to emit warnings anytime a flag alias is used