arcanis / clipanion

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

Multiple multi-level paths in one command causes duplicates in help text #126

Open d-fischer opened 2 years ago

d-fischer commented 2 years ago

Description

If you define multiple nested paths for a command, and then try to execute a shared partial path of it, you get an error message where the first path is displayed multiple times.

Source

const { Builtins, Command, runExit } = require('clipanion');

runExit(
    { binaryName: 'test' },
    [
        Builtins.HelpCommand,
        class extends Command {
            static paths = [['foo', 'bar'], ['foo', 'baz']];
            async execute() {
                console.log('hi');
            }
        }
    ],
    ['foo']
);

Expected result

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

$ test foo bar

While running foo

or

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

  0. test foo bar
  1. test foo baz

While running foo

It's really up to you (or a config option?) whether to include multiple paths for one command in the help text.

Actual result

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

  0. test foo bar
  1. test foo bar

While running foo

As you can see, while baz isn't shown at all (which, arguably, might be fine), bar is shown twice.