Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Allow variadic arguments without spread operator #160

Open
nbbaier opened this issue May 27, 2024 · 0 comments
Open

FR: Allow variadic arguments without spread operator #160

nbbaier opened this issue May 27, 2024 · 0 comments

Comments

@nbbaier
Copy link

nbbaier commented May 27, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant