parsing of strings containing flag notation
See original GitHub issue#!/usr/bin/env node
const mri = require('mri')
console.log(process.argv)
console.log(mri(process.argv.slice(2)))
./args.js -a -b '-c foo'
[
'/usr/local/Cellar/node/16.0.0_1/bin/node',
'/Users/j/web/pev2-cli/foo.js',
'-a',
'-b',
'-c foo'
]
{
_: [],
a: true,
b: true,
c: true,
' ': true,
f: true,
o: [ true, true ]
}
Is that intended?
I would have expected this:
{
_: ['-c foo'],
a: true,
b: true
}
Or maybe this (but I find the result above much more intuitive):
{
_: [],
a: true,
b: true,
c: 'foo'
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
How to use flags with python's regular expressions in string ...
I was wondering how to write more complex regular expressions using this notation, specifically how to use the IGNORECASE flag for the RE....
Read more >Parse a string in exponential notation with only the AllowExponent ...
1. Parse a string in exponential notation with the AllowExponent and Number flags. 2. Parse a currency value with leading and trailing white...
Read more >14.8 Command-Line Parsing - Brown CS
Command-line strings starting with - or + are parsed as flags, but arguments to flags are never parsed as flags, and integers and...
Read more >How To Use the Flag Package in Go - DigitalOcean
The parsing phase is handled by the Parse() function. To illustrate, you'll create a program that defines a Boolean flag that changes the ......
Read more >flag - Go Packages
TextVar defines a flag with a specified name, default value, and usage string. The argument p must be a pointer to a variable...
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 would also like to add a simpler case, in which
mri
parses incorrectly:The hyphen (
-
) is very common to indicatestdin
orstdout
, but when parsed withmri
, the result is:Whereas,
-
should be part of_
key.That doesn’t solve my problem unfortunately, because I would like to treat
-b
like any other option/flag: I want to be able to put other flags behind. Using--
defeats the point of using a flag and leveragingmri
’s parsing logic.