dthree / vorpal

Node's framework for interactive CLIs
http://vorpal.js.org
MIT License
5.64k stars 280 forks source link

Option parsing works unexpected since v1.10.0 #170

Closed hrbu closed 8 years ago

hrbu commented 8 years ago

Since version 1.10.0 vorpal seems to have a bug when parsing options from the passed arguments. Until v1.9.7 it works as expected. Since v1.10.0 (including the currently latest v1.11.3) the values of options are not parsed correctly.

I have a command like this ...

vorpal
  .command('logs <cluster>')
  .option('-v, --verbose', 'Show details.')
  .option('--tail', 'Number of lines to show from the end of the logs for each container.')

vorpal-1.9.7

passed args:

[ '/usr/local/bin/node',
  '/opt/base/opt/base-cli/base-cli.js',
  'logs',
  'dev',
  '--tail',
  '100' ]

vorpal parsed args:
{ options: { tail: 100 }, cluster: 'dev' }

vorpal-1.10.0

passed args:

[ '/usr/local/bin/node',
  '/opt/base/opt/base-cli/base-cli.js',
  'logs',
  'dev',
  '--tail',
  '100' ]

vorpal parsed args:
{ options: { tail: true }, cluster: 'dev' }

Note the unexpected value of tail ...

dthree commented 8 years ago

What happens if you edit your command like this:

vorpal
  .command('logs <cluster>')
  .option('-v, --verbose', 'Show details.')
  .option('--tail [amount]', 'Number of lines to show from the end of the logs for each container.')

Can you please try this and post the result?

hrbu commented 8 years ago

vorpal-1.10.0 && vorpal-1.11.4

vorpal parsed args:
{ options: { tail: 100}, cluster: 'dev' }

OK. When providing a parameter for the option, vorpal parses the value as expected. I would prefer any option declaration without parameter to be handled as an optional one.

dthree commented 8 years ago

@hrbu this creates additional problems, and this is why this change was actually a bug fix. Is it possible to simply amend your app to include declaring the parameters? Thanks.

hrbu commented 8 years ago

Yes, possible. Thanks for your support.