-
Notifications
You must be signed in to change notification settings - Fork 74
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
array support #62
Comments
+1 |
Could it be more intuitive to provide it as follows on cli: Maybe we have to escape the paranthesis. |
you would then have no matches error on Bash/Zsh. A better solution would be |
Pls check out this small piece of code (index.js): #!/usr/bin/env node
'use strict';
var cli = require('cli');
var path = require('path');
var assert = require('assert');
var usage = path.basename(__filename) + ' [OPTIONS]';
var packagePath = __dirname + '/package.json';
var options = {
a: [ 'a', 'The a', 'string', '[]' ], // of course, there needs to be the native support for Array here later!
b: [ 'b', 'The a', 'string', 'b' ]
};
function main(args, options) {
cli.info(JSON.stringify(options, null, 4));
options.a = JSON.parse(options.a);
cli.info(JSON.stringify(options, null, 4));
assert(Array.isArray(options.a), 'options.a should be array');
}
cli.setUsage(usage);
cli.setApp(packagePath);
cli.parse(options);
cli.main(main); When I call it like this:
or even unescaped double quotes:
it prints:
At least, couldn't that be a starting point to implement in cli? Or am I missing something here...? BTW, I tried that on Zsh. |
@coolaj86 Good requirement! I have supported such idea in package commandos with MULTIPLE decorator: const commandos = require('commandos');
const options0 = commandos.parse('test -a foo', { options: [ '-a MULTIPLE' ] });
// options0 := { $: [] }
const options1 = commandos.parse('test -a foo', { options: [ '-a MULTIPLE' ] });
// options1 := { a: [ 'foo' ], $: [] }
const options2 = commandos.parse('test -a foo -b bar', { options: [ '-a MULTIPLE' ] });
// options2 := { a: [ 'foo', 'bar'], $: [] } The returned |
If you ever have a rainy day and want to implement an 'array' type such that I could do
-a foo -a bar
to produce[ "foo", "bar" ]
would be awesome.The text was updated successfully, but these errors were encountered: