question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Option function and default parameter is not executed

See original GitHub issue

In 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:open
  • Created 8 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
eliperelmancommented, Dec 2, 2015

What’s interesting about this approach is that the same function passed to .option could be used for validation as well. Maybe it could be sniffed to see if value instanceof Error, then return the error message instead of “missing required option”. Just an idea.

0reactions
eliperelmancommented, May 24, 2016

@dthree any more thoughts on this? Just had this come up on another project that would be useful.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found