Skip to content
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

options parse, #97

Open
mromanuk opened this issue Apr 3, 2017 · 1 comment
Open

options parse, #97

mromanuk opened this issue Apr 3, 2017 · 1 comment

Comments

@mromanuk
Copy link

mromanuk commented Apr 3, 2017

Is there a way to tell if the parsed options, were default or set by the user?

const options = cli.parse({
	name:     [ 'n', 'instance name', 'string', 'Alice'],
}, [commands...]);

For example I need to know if --name Alice and my options object become:

{customer: 'Alice'}

I would like to know if it was set in the cli or it is a default option.

Something like this::

{{customer: 'Alice', setByDefault: true}, {otherOption: ..., setByDefault: false}}
@YounGoat
Copy link

@mromanuk Is it really meaningful to know whether the option's value is explicit set in CLI or by default? If it is really necessary for you, the following example based on commandos may be useful to you:

const commandos = require('commandos');
const cmd = commandos.parse({ options: [ '--name' ] });
// Only options which are multiple, or with default values, 
// or set in CLI will occur in the returned value.
if (!cmd.hasOwnProperty('name')) {
	cmd.name = 'Alice';
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants