arcanis / clipanion

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

List commands with common prefix on `--help` #148

Closed Drarig29 closed 1 year ago

Drarig29 commented 1 year ago

Closes #110

This PR adds new possible outputs for -h/--help.

my-cli foo --help can now return:

Multiple commands match your selection:

  0. my-cli foo
  1. my-cli foo one
  2. my-cli foo two

Run again with -h=<index> to see the longer details of any of those commands.

How?

This PR adds a new possible transition in the state machine.

For every part of a path (except the last one), -h/--help can now be passed as a leaf. Said differently: nothing is allowed after -h/--help when it breaks a path apart.

Let a command be foo bar baz --arg #0 (i.e. paths = [["foo", "bar", "baz"]]):

stateDiagram-v2
  foo
  state "--help (new)" as h1
  foo --> h1
  foo --> bar
  bar
  state "--help (new)" as h2
  bar --> h2
  bar --> baz
  baz
  state "--help" as h3
  baz --> h3
arcanis commented 1 year ago

Looks great, thanks!