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

variadic args prevent any subsequent options #716

Open
andykais opened this issue Jun 18, 2024 · 2 comments
Open

variadic args prevent any subsequent options #716

andykais opened this issue Jun 18, 2024 · 2 comments

Comments

@andykais
Copy link

a sample script like this:

import * as cliffy from 'jsr:@cliffy/[email protected]'

const cli = new cliffy.Command()
  .name('test')
  .option('--files <...files:string>', 'A list of files to watch')
  .option('--foobar', 'A foobar')
  .action(opts => {
    console.log({opts})
  })

cli.parse()

when called like so: deno run --check test.ts --files foo,bar --foobar produces the following output

{ opts: { files: [ "foo,bar", "--foobar" ] } }

This means that users of a cli tool need to know which args are variadic and remember to put them last. I also imagine this means theres no way to specify more than one option that accepts variadic arguments. One possible way to handle these cases would be if I could specify a delimeter for variadic args. E.g. a comma (you can see in the example above that comma separated values are currently read as a single value. To avoid making it break existing clis, this could be an optional arg on the option method.

Also, while testing this I realized that the same command with an = character hits an infinite recursion loop:
deno run --check test.ts --files=foo,bar

error: Uncaught (in promise) RangeError: Maximum call stack size exceeded
      function parseValue(
               ^
    at parseValue (https://jsr.io/@cliffy/flags/1.0.0-rc.4/flags.ts:411:16)
    at parseNext (https://jsr.io/@cliffy/flags/1.0.0-rc.4/flags.ts:347:20)
    at parseNext (https://jsr.io/@cliffy/flags/1.0.0-rc.4/flags.ts:373:11)
    at parseNext (https://jsr.io/@cliffy/flags/1.0.0-rc.4/flags.ts:373:11)
    at parseNext (https://jsr.io/@cliffy/flags/1.0.0-rc.4/flags.ts:373:11)
    at parseNext (https://jsr.io/@cliffy/flags/1.0.0-rc.4/flags.ts:373:11)
    at parseNext (https://jsr.io/@cliffy/flags/1.0.0-rc.4/flags.ts:373:11)
    at parseNext (https://jsr.io/@cliffy/flags/1.0.0-rc.4/flags.ts:373:11)
    at parseNext (https://jsr.io/@cliffy/flags/1.0.0-rc.4/flags.ts:373:11)
    at parseNext (https://jsr.io/@cliffy/flags/1.0.0-rc.4/flags.ts:373:11)
@andykais
Copy link
Author

another option would be allowing commands to be specified more than once. E.g.

deno run --check test.ts --watch foo --watch bar

@Arnaud73
Copy link

Have you tried .option('--files <files:string[]>', 'A list of files to watch') instead?

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

2 participants