tj / commander.js

node.js command-line interfaces made easy
MIT License
26.38k stars 1.69k forks source link

Short option name with single character or multiple characters have different result #2211

Open Brucedayton opened 4 weeks ago

Brucedayton commented 4 weeks ago

Steps to reproduce:

  1. Have command with a required option argument with a short name (e.g -a).
  2. Have command with a required option argument with a short name (e.g -bc). Run the command with the option argument but with no space after the argument name (e.g commandname -asdf). Run the command with the option argument but with no space after the argument name (e.g commandname -bcd).

Actual result:

  1. Command runs and option argument -a has value "sdf".
  2. error: unknown option '-bcd'

Can short option with single character report the same error like issue 2?

shadowspawn commented 4 weeks ago

The simple answer is short options should be a single character. This is not currently treated as an immediate error, but may be in the future.

From the README:

Each option can have a short flag (single character) and a long name

And listed as explicitly deprecated:

Short option flags like -ws were never supported, but the old README did not make this clear. The README now states that short options are a single character.

shadowspawn commented 4 weeks ago

(Thanks for the clear description.)

shadowspawn commented 2 weeks ago

Can short option with single character report the same error like issue 2?

No, an option with a required option argument looks for a value with or without a space. So these are equivalent:

util -a AAA
util -aAAA

This is a widely supported syntax, although I do consider it an advanced syntax. When you don't know about it, the lack of an error for an unlucky typo can be surprising.

Brucedayton commented 1 week ago

Thank you for the detailed explanation