-
Notifications
You must be signed in to change notification settings - Fork 105
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
Support positional args #97
Comments
I think they can be emulated via Ahh, with |
That emulation technique is very clever! One drawback with it, however, is that it cannot coerce the arguments to different data types (which I realized after trying it). |
I'd also love to see this. I have a set of commands of the form
and command-line-args' if (mainCommand.command === "cmd1") {
const cmd1 = commandLineArgs([
{ name: "positional1", defaultOption: true },
{ name: "positional2", defaultOption: true }
], { argv: mainCommand._unknown })
} but this gives an error saying that only one option can be a I'd rather not have to use |
Hi @Myaamori, positional args are planned for the next release. In the meantime, you can emulate positional args with code like this. const commandLineArgs = require('command-line-args')
const optionDefinitions = [
{
name: 'positionals',
multiple: true,
defaultOption: true
}
]
const options = commandLineArgs(optionDefinitions)
console.log(options)
/* validate positionals */
const validArgs = options.positionals
&& options.positionals.length === 2
&& options.positionals.every(p => p)
if (validArgs) {
console.log('Valid args')
} else {
throw new Error('Exactly two args are required.')
} Example invocations:
|
Support positional args, similar to what is available in argparse.
The text was updated successfully, but these errors were encountered: