-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
parsing of strings containing flag notation #14
Comments
Hey, sorry haven't had a chance to look yet. I think you'd have to do this: Anything after a |
That doesn't solve my problem unfortunately, because I would like to treat |
I would also like to add a simpler case, in which ./args.js - The hyphen ( { _: [] } Whereas, |
I'm not sure that there's a way to interpret that string the way you want. As you can see from the ./args.js -a -b '-c foo'
[
'-a',
'-b',
'-c foo'
] MRI just sees a string that starts with a dash, which is how it identifies an option. It could peek further into the string to check for illegal characters but I don't think that will resolve all possibilities. Such as: ./args.js -a -b '-abc' You can still pass a string like that, but it requires you to use the ./args.js -a -b='-c foo' Alternatively you could pass your arguments with a different syntax (or prefix) and transform them before passing them on. ./args.js -a -b 'c=foo&d=bar'
./args.js -a -b '$ -c foo -d bar' Which requires a little bit more thought, but it perhaps less confusing to an end user than requiring that one option MUST use an equals sign. |
Maybe I'm missing something here, but there should be a way to support even the use case that I have proposed: Implement parsing with state, as in "Do I expect a potential argument now?". Am I wrong? |
Okay well let's talk through the parsing state quickly to explain how it makes the decision. /example -b '-d foo'
# argv = ['node', '/example', '-b', '-d foo'] We ditch the first 2 args because they aren't useful to us, then we pass the rest to MRI. Internally the state flow goes like this.
The troublesome step for you is 4, as it determines that what you want to be the value of the option isn't a valid value. It does this by checking for the existence of a I mention that using A possible option would be to tell MRI that this option is always a dumb string field and it should parse it as such. mri(['-b', '-abc'], { string: ['b'] }) But this doesn't match up with how MRI actually reads and interprets the values at the moment, they are read as a piece of text and then interpreted afterwards and hence don't affect how the command itself it actually parsed. Adding this effect causes strange side effects if a user makes a mistake. Like in the below example. example -b '-d val'
# argv [ '-b', '-d val' ]
# old { b: true, d: true, v: true, a: true, l: true }
# proposed { b: '-d value' }
example -b -d val
# argv ['-b', '-d', 'val']
# old { b: true, d: 'val' }
# proposed { b: '-d', _: [ 'val' ] } Note that the second doesn't include quote marks, but the modification has still changed how the command is interpreted. |
./args.js -a -b '-c foo'
Is that intended?
I would have expected this:
Or maybe this (but I find the result above much more intuitive):
The text was updated successfully, but these errors were encountered: