tj / commander.js

node.js command-line interfaces made easy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optional array argument is always defined

garysassano opened this issue · comments

I've noticed a difference between an optional standard argument and an array argument.

program
    .command("test")
    .argument("[entrypoint]")

In this case entrypoint = undefined if the user doesn't specify any argument.

program
    .command("test")
    .argument("[entrypoint...]")

In this case entrypoint = [] if the user doesn't specify any argument, whereas I expected it to be undefined.

Yes, the variadic optional argument has behaved like that since it was added.

(It would also have been reasonable to return undefined for no arguments, as you expected.)