arcanis / clipanion

Type-safe CLI library / framework with no runtime dependencies
https://mael.dev/clipanion/
1.11k stars 64 forks source link

"Unknown Syntax Error: Command not found" when running a command with a required param missing #136

Open jakub-g opened 1 year ago

jakub-g commented 1 year ago

This is a followup of #101 (see my comment)

When the command yarn cli foo has a required param

name = Option.String('--name', { required: true });

and it's run without it, the error message is not great

yarn cli foo       
Unknown Syntax Error: Command not found; did you mean:

$ yarn cli foo <--name #0>
While running foo

I think in this case, the behavior should be the same as if yarn cli foo --help.

SeinopSys commented 1 year ago

In my case there was an accidental lack of space between two arguments, e.g. --foo opt1--baz opt2 which lead to a similar message despite both --foo and --baz being optional. The error message was basically 2 of the same alternate options:

Unknown Syntax Error: Command not found; did you mean one of:

  0. /usr/local/bin/node /home/user/index.js my-command [--foo #0] [--baz #0]
  1. /usr/local/bin/node /home/user/index.js my-command [--foo #0] [--baz #0]

Edit: Turns out the issue was a red herring, the CLI abstraction I was using passed a Bash substitution argument as a literal. I verified this by logging process.argv and saw […, '--baz $(cat', 'file.txt)'] in the value received by the script. I adjusted the code to accept the file name as parameter directly without having the command interpreter reading it and it's working well since.