arcanis / clipanion

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

Help flag on command doesn't work with required flags #100

Closed Embraser01 closed 6 months ago

Embraser01 commented 3 years ago

I'm using clipanion in https://github.com/Embraser01/typoas and the -h flag at the end of a command like yarn dlx @typoas/cli generator -h display:

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

  0. @typoas/cli generate <-i,--input #0> <-o,--output #0> <-n,--name #0> [--js-doc] [--only-types]
  1. @typoas/cli -h
  2. @typoas/cli -v

While running generator -h

instead of displaying the usage of the command. I succeeded to reproduce the bug in the should display the usage per-command:

https://github.com/arcanis/clipanion/blob/master/tests/advanced.test.ts#L95-L110

By changing it to:

it(`should display the usage per-command`, async () => {
  const cli = new Cli();
  cli.register(Builtins.HelpCommand);

  class CommandA extends Command {
    static paths = [[`foo`]];

    static usage: Usage = {description: `My command A`};

    foo = Option.Boolean(`--foo`, {required:true});
    async execute() {log(this);}
  }

  cli.register(CommandA);

  expect(await runCli(cli, [`foo`, `-h`])).to.equal(cli.usage(CommandA));
  expect(await runCli(cli, [`foo`, `--help`])).to.equal(cli.usage(CommandA));
});

I found 2 issues here:

romdej commented 7 months ago

Helllo @Embraser01, the issue seems unreproducible. Well, the error still the same with yarn dlx @typeoas/cli generator -h but it's only because there is no command matching the path generator. If I use yarn dlx @typeoas/cli generate -h I have no issue.

For the case where you were able to reproduce the issue in the mentioned test, I think it's due the missing option detailed: true in the cli.usage calls.

Embraser01 commented 6 months ago

Couldn't reproduce, I must have been tired 😅, let me close this