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

fix: handling quoted strings and options validation for comma-delimited multiple-flag #614

Merged
merged 5 commits into from
Feb 7, 2023

Conversation

mshanemc
Copy link
Member

@mshanemc mshanemc commented Feb 7, 2023

  1. --multiFlag would validate options agains the combined input BEFORE splitting when it used a delimiter.
  2. strings can be double-quoted when they contain spaces. This removes surrounding quotes from the items before validating against the options.

side note about error messages assertion changes:
test cases would run find from yarn test but fail when running the individual test becuase of ASCII color codes in the results. They've been modified to "include" the expected strings to make them color-blind

fixes forcedotcom/cli#1936

mdonnalley
mdonnalley previously approved these changes Feb 7, 2023
it('allowed options on multiple', async () => {
const out = await parse(['--foo', 'a', '--foo=b'], {
flags: {
foo: Flags.custom({multiple: true, parse: async i => i, options: ['a', 'b']})(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason for using Flag.custom and defining a parse? It's not an issue, it just would be more concise to do this:

Flags.string({multiple: true, options: ['a', 'b']})

const values = await Promise.all(
input.split(flag.delimiter).map(async v => this._parseFlag(v.trim(), flag, token)),
input.split(flag.delimiter).map(async v => this._parseFlag(v.trim().replace(/^"(.*)"$/, '$1'), flag, token)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mshanemc should this also consider signle quotes, 'a b' 'c d'?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I think so. posix-shells could

@mdonnalley mdonnalley merged commit c32ab9d into main Feb 7, 2023
@mdonnalley mdonnalley deleted the sm/multiple-options branch February 7, 2023 17:42
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.

InvalidPackageIdError: The id [My] is invalid.
3 participants