yargs / yargs/yargs-parser

Optional choices for array

Open
#220 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature triaged
Dominant language
JavaScript
Stars
519
Forks
129
Avg merge
1h 34m
Merged PRs (30d)
1

Description

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 yargs/yargs-parser#219

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the two create-index command examples and compare how array choices handle the following positional argument. Review the related yargs/yargs-parser#219 discussion and the parser's existing choice and positional-argument tests; done means an optional choice can leave unmatched trailing arguments positional while still rejecting an unmatched first array value.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.