args icon indicating copy to clipboard operation
args copied to clipboard

Options' defaults not used when using command with init function

Open barbu110 opened this issue 6 years ago • 3 comments

Hello!

First of all, I'd like to say I really like args. It has a few things it's not doing correctly right now, but it's going on a great path.

I created an executable, let's call it myexec:

args.options([{
  name: 'target',
  default: 'dev',
  description: '...',
}]);

args.command('cmd', 'description', (name, sub, options) => {
  console.log(options);
});

Running it goes as follows:

$ ./myexec cmd
{}

The options object should contain the default value of target and it's missing. I think this is a bad problem unless a simple workaround exists. What do you think?

barbu110 avatar Feb 20 '19 11:02 barbu110

Hey @barbu110, the correct property for defining a default value is defaultValue. You've used default. Can you try again and tell us if this fixed your issue?

ntwcklng avatar Mar 02 '19 08:03 ntwcklng

ping @barbu110

ntwcklng avatar Jun 18 '19 11:06 ntwcklng

even though his example is wrong, he's correct. This though seems to be by design

  // If sub command is defined, run it
  if (defined) {
    this.runCommand(defined, optionList)
    return {}
  }

  // Hand back list of options
  return optionList

RickeyWard avatar Jul 27 '22 23:07 RickeyWard