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

Optional choices for array #220

Open
laggingreflex opened this issue Dec 15, 2016 · 1 comment
Open

Optional choices for array #220

laggingreflex opened this issue Dec 15, 2016 · 1 comment

Comments

@laggingreflex
Copy link
Contributor

I have a config like this:

filetype: {
  choices: ['.js', '.jsx'],
  type: 'array'
},
recursive: {
  type: 'boolean'
}, 

So this works:

create-index --filetype .js .jsx --recursive ./src

But this throws an error:

create-index --filetype .js .jsx ./src
Invalid values:
  Argument: filetype, Given: "./src", Choices: ".js", ".jsx"

There should be an option to make the choices be "optional" rather than throw an error. If it doesn't find a match it should consider the rest of the arguments to be positional arguments. This can be especially useful for arrays as shown in above example. It should throw (in case of an array) only if the first argument doesn't match.

This could possibly address #219

@bcoe bcoe transferred this issue from yargs/yargs Nov 10, 2019
@bcoe bcoe added the feature label Nov 10, 2019
@bcoe
Copy link
Member

bcoe commented Nov 10, 2019

With commands we're more explicit, where only the last positional argument can be veridadic, so you can do this:

[item] [item2...]

but but:

[item...] [item2...]

☝️ in general, I think this is a better approach for handling variable length input, and I'm not a huge fan of the array argument type.

I'd rather that folks are more explicit and specify --item 1 --item 2, rather than --item 1 2; I'm wondering if perhaps we could deprecate the variable --item 1 2 3 array parsing, in favor of this; CC: @juergba.

@bcoe bcoe added the triaged label Nov 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
@bcoe @laggingreflex and others