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

Warning mistakenly displayed when using a flag that starts with a deprecated alias #1204

Closed
alan-morey opened this issue Sep 27, 2024 · 2 comments · Fixed by #1208
Closed
Labels
bug Something isn't working

Comments

@alan-morey
Copy link

alan-morey commented Sep 27, 2024

Describe the bug
While working on a Salesforce CLI plugin I ran into the following bug regarding deprecated flag warning messages.

Given a flag, foo-bar is added to a command and has an alias, foo and the flag is configured with deprecateAliases: true, when executing the command with --foo the deprecated flag warning message is displayed as expected.

However, when executing the command with --foo-bar the deprecated flag warning message is displayed saying:

Warning: The "--foo" flag has been deprecated. Use "--foo-bar" instead.

To Reproduce
Steps to reproduce the behavior:

  1. Add a flag to a command with configuration as follows:
    'foo-bar': Flags.boolean({
      summary: 'summary',
      deprecateAliases: true,
      aliases: ['foo']
    }),
  1. Execute the command with flag --foo-bar
$ ./bin/dev.js mycommand --foo-bar
  1. Warning is displayed

Warning: The "--foo" flag has been deprecated. Use "--foo-bar" instead.

Expected behavior
Warning should not be displayed when --foo-bar flag is used as the flag is not marked as deprecated, only the alias flag --foo should be considered deprecated.

Environment (please complete the following information):

  • OS & version: Ubuntu 22.04.5 LTS
  • Shell/terminal & version zsh 5.8.1 (x86_64-ubuntu-linux-gnu)

package.json dependencies

  "dependencies": {
    "@jsforce/jsforce-node": "^3.4.1",
    "@oclif/core": "^4.0.19",
    "@salesforce/apex-node": "^8.1.4",
    "@salesforce/core": "^8.4.0",
    "@salesforce/sf-plugins-core": "^11.3.6",
    "@salesforce/ts-types": "^2.0.10"
  },
  "devDependencies": {
    "@oclif/plugin-command-snapshot": "^5.2.8",
    "@salesforce/cli-plugins-testkit": "^5.3.19",
    "@salesforce/dev-scripts": "^10.2.9",
    "@salesforce/ts-sinon": "^1.4.24",
    "@types/node": "^22.4.0",
    "@types/sinon-chai": "^3.2.12",
    "eslint": "^8.56.0",
    "eslint-plugin-sf-plugin": "^1.19.0",
    "oclif": "^4.14.8",
    "prettier": "^3.3.3",
    "pretty-quick": "^4.0.0",
    "sinon-chai": "^4.0.0",
    "ts-node": "^10.9.2",
    "typedoc": "^0.26.5",
    "typescript": "^5.4.5"
  },

Additional context
Looks like source of problem is related to use of startsWith on line 339.

core/src/command.ts

Lines 339 to 346 in 7ede2e5

const foundAliases = aliases.filter((alias) => this.argv.some((a) => a.startsWith(alias)))
for (const alias of foundAliases) {
let preferredUsage = `--${flagDef?.name}`
if (flagDef?.char) {
preferredUsage += ` | -${flagDef?.char}`
}
this.warn(formatFlagDeprecationWarning(alias, {to: preferredUsage}))

@mdonnalley mdonnalley added the bug Something isn't working label Sep 30, 2024
Copy link

git2gus bot commented Sep 30, 2024

This issue has been linked to a new work item: W-16866149

@mdonnalley
Copy link
Contributor

@alan-morey thanks for the detailed writeup! I'll have a PR up shortly to fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants