-
Notifications
You must be signed in to change notification settings - Fork 10
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
refactor!: rework results to have parsedOptions property and store true in values for boolean options #80
Conversation
- Is `--` included as a positional? | ||
- no | ||
- Is `program -- foo` the same as `program foo`? | ||
- yes, both store `{positionals:['foo']}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems wrong; — means “stop parsing options”; everything after it should be untouched.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean.
The QA don't include an example storing an (otherwise) option as a positional, is that what you were expecting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What i mean is, program a b c
should have three positionals (a, b, and c) - but program -- a b c
should only have one positional, the string "a b c", so it can be passed verbatim to something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, combining the strings like that would lose the information about the separate arguments and require another interpretation step to split them up again.
This might be too opaque, but imagine implementing subcommands:
// utility --option1 -- dispatch --option2
const result1 = parseArgs({ options: mainOptions );
if (result1.positionals[0] === 'dispatch') {
const result2 = parseArgs({ args: result1.positionals.slice(1), options: dispatchOptions });
}
A different example. The --
turns off option processing and the remaining arguments end up untouched and treated as positionals, so these three examples all have the same result. There isn't anything special about the handling of arguments after the --
than before the --
other than no option processing.
utility foo bar -- --unprocessed-option
utility foo -- bar --unprocessed-option
utility -- foo bar --unprocessed-option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's the idea. They're going to be passed to another program, so THAT program will be interpreting them on its own - perhaps with different rules than the current one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally that other program will be interpreting an array of arguments, not a single string?
The --
stops option detection. It is not a marker for separate collection of arguments into another structure.
(There are some programs that treat --
as a marker for separate processing, but in my experience that is unusual. It is easy to form the impression programs work that way though, since for easy reading the --
is often put before the passthrough arguments!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One way of thinking about --
is that it is another user-level intervention. No author action required.
- suppress shell interpretation of special characters in arguments: quote argument
- suppress utility interpretation of arguments as options:
--
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example behaviours of reference implementations added to: #58 (comment)
Closing in favour of #83 |
See #70 for longer description.
In parse results, minor code changes:
flags
toparsedOptions
true
invalues
for boolean options (rather thanundefined
)In README, more churn:
parsedOptions
, not just boolean options--
description to match current implementationAdded the examples in the README to a file so can confirm actual behaviour!