deno-cliffy icon indicating copy to clipboard operation
deno-cliffy copied to clipboard

Args returns `any[][]`

Open UltiRequiem opened this issue 2 years ago • 1 comments

With the following code

const {  args } = await new Command()
  .name("redirector")
  .version("0.1.0")
  .description("Create your own redirector service 🚀")
  .arguments("<...urls>")
  .parse(Deno.args);

console.log(args)

And executing it like this

deno run src/cli/redirector.ts build jeje

I got

[ [ "build", "jeje" ] ]

Why is the reason for this? Is not a big problem but is this the intended behavior?

What I would spect is

 [ "build", "jeje" ]

UltiRequiem avatar Mar 24 '22 15:03 UltiRequiem

Looks like this is intended: https://cliffy.io/[email protected]/command/commands#variadic-arguments

arguments can include explicit positional arguments, with a variadic option at the end. The resulting args array will have exactly one value for each item in the list – the variadic argument is expressed as a nested array.

For example, consider this command:

const { args } = await new Command()
  .arguments("<arg1> <arg2> <...extras>")
  .parse(Deno.args);

console.log(args)

When you run:

deno run rhyme.ts one two buckle my shoe

it outputs:

[ "one", "two", [ "buckle", "my", "shoe" ] ]

And the type of args is actually [string, string, string[]]

Screen Shot 2022-06-30 at 11 08 27 AM

avery-pierce avatar Jun 30 '22 16:06 avery-pierce