Skip to content
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

Merged
merged 5 commits into from Oct 28, 2022
Merged

Conversation

mdonnalley
Copy link
Contributor

  • Adds deprecateAliases to Command - allowing you to emit warnings anytime a command alias is used
  • Adds deprecateAliases to all flags - allowing you to emit warnings anytime a flag alias is used
  • Parser is now interprets single character aliases as short char flags

@mdonnalley mdonnalley self-assigned this Oct 28, 2022
mshanemc
mshanemc previously approved these changes Oct 28, 2022
src/command.ts Outdated

const deprecateAliases = this.ctor.flags[flag]?.deprecateAliases
const aliases = this.ctor.flags[flag]?.aliases ?? []
if (deprecateAliases && aliases) {
Copy link
Member

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, '')))
Copy link
Member

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 - ?

Copy link
Contributor Author

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

Copy link
Member

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])
Copy link
Member

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.

https://github.com/salesforcecli/plugin-source/blob/f5f681b19bcae6a98c25e45e7b461a624f1c2920/test/commands/source/cancel.test.ts#L43

One of those "I'm super cautious about asserting things to TS"

Copy link
Member

@mshanemc mshanemc left a 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.

@mshanemc mshanemc merged commit aed5db3 into main Oct 28, 2022
@mshanemc mshanemc deleted the mdonnalley/deprecation-warnings branch October 28, 2022 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants