Option function and default parameter is not executed
See original GitHub issueIn source diving the arguments passed to command.option, it appears that it accepts a 3rd and 4th parameter for defining a function and default value for the option, but it appears that these aren’t actually being executed. In this test case, I was unable to get a default value or have the function execute. Am I doing something wrong, or is this just not supported yet?
#! /usr/bin/env node
let Vorpal = require('vorpal');
let cli = new Vorpal();
cli
.command('test')
.description('A test')
.option('--url <url>', 'Some url', function(val) { cli.log('VALUE!', value); }, 'http://some.url')
.action(function(args, done) {
this.log('URL:', args.options.url);
done();
});
cli.parse(process.argv);
$ ./cli test
URL: undefined
$ ./cli test --url other.url
URL: other.url
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
Default parameters - JavaScript - MDN Web Docs
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
Read more >Javascript Functions and default parameters, not working in IE ...
Default parameter assignment syntax is likely coming in ECMAScript 6. Share.
Read more >Options not working in user-defined function for SymbolName
I have another function in which I would like it to return a Row[...] with objectName[symbol] and value Evaluate[symbol] but I would also...
Read more >Default arguments - cppreference.com
For non-template functions, default arguments can be added to a function that was already declared if the function is redeclared in the same ......
Read more >Understanding Default Parameters in JavaScript - DigitalOcean
These allow developers to initialize a function with default values if the arguments are not supplied to the function call.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

What’s interesting about this approach is that the same function passed to
.optioncould be used for validation as well. Maybe it could be sniffed to see ifvalue instanceof Error, then return the error message instead of “missing required option”. Just an idea.@dthree any more thoughts on this? Just had this come up on another project that would be useful.