FR: Allow variadic arguments without spread operator
nbbaier opened this issue · 0 comments
nbbaier commented
Issue Type
- [x ] Feature Request
Expected
I'd like to be able to do the following:
cli.command("echo [arg]", "echo the input back", { variadic: true }).action((arg: string[]) => {
console.log(arg);
console.log(arg.join(" "));
});
$ cli this is a message
[ "this", "is", "a", "message" ]
this is a message
$ cli "this is a message"
[ "this is a message" ]
this is a message
In other words, allow the final argument of a command to be marked as variadic without the spread operator. This would make things a little more ergonomic when working with commands where you're input sentences/longer strings - you could do either.
Actual
Currently, the behavior is of course available, but we need to use the spread operator convention.
cli.command("echo [...arg]", "echo the input back").action((arg: string[]) => {
console.log(arg);
console.log(arg.join(" "));
});
The issue with this convention is that [...arg]
seems to be imply that the arguments are separate conceptual units.
cli
Usage:
$ cli <command> [options]
Commands:
echo [...arg] echo the input back
For more info, run any command with the `--help` flag:
$ sample-cli echo --help
This is not the case when we're entering single sentences, where a set of strings is separated by spaces. It's nice to just be able to do $ cli echo this is a sentence that I want to type unquoted
.