Handle boolean array arguments better
See original GitHub issueThis is justified since Boolean
types already get a bit of special treatment.
In the case I want multiple levels of verbosity, for example, the following should work:
// ./my-program -vvvv
const arg = require('arg');
const args = arg({
'-v': [Boolean]
});
console.log(args);
/*
{
_: [],
'-v': 4
}
*/
Currently, you have to do -v -v -v -v
separately, and in turn you get [true, true, true, true]
, which isn’t exactly elegant.
Issue Analytics
- State:
- Created 5 years ago
- Comments:16 (16 by maintainers)
Top Results From Across the Web
Boolean arrays — Coding for Data - 2020 edition
Now we know about function arguments, and arrays, we can simplify the list version, ... are_three is a Boolean array because it contains...
Read more >How to improve logic to check whether 4 boolean values ...
I would make 2 improvements: 1: assign values to scenarioX with an explicit indication of boolean values used, e.g. SCENARIO_2 = true <<...
Read more >Boolean Array Example - YouTube
Declare and instantiate a boolean array. Access and modify the array by indices. Print an array using a for-loop.
Read more >Better Boolean Variable Names | SamanthaMing.com
Coming up with good variable names can always be a challenge. So there is some convention you can follow that makes the process...
Read more >Solved: How to use Pass/Fail tests with an Array of Boolean in ...
Re: How to use Pass/Fail tests with an Array of Boolean in which each boolean has an expected value of true/false? You can...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have completed this, but I could use a few more use-cases to ensure it serves the correct purpose.
Using your example above, should
./my-program -vvvv -v
output'-v': 5
?What if the flag
'-vvv'
exists? Should the following return case 1 or case 2?Don’t want to miss an edge case 😅
Agreed that returning a number for
[Boolean]
flags seems strange. Seems like the natural solution is to return an array of booleans[true, true, true, ...]
and let the user call.length
on it themselves.The core of the issue still exists though: repeating single-hyphen flags should push additional true values onto that array.