arcanis / clipanion

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

Nested commands like `gh auth login` #152

Closed talentlessguy closed 1 year ago

talentlessguy commented 1 year ago

Hi, this is not a bug but a question. I couldn't find in the docs nor in issues (maybe my keywords are wrong) but I can't see how to implemented nested commands to be able to handle stuff like this:

$ gh auth login --foo=bar
$ gh auth logout

Where help would display different help messages for each command, aka gh auth login --help and writing gh auth would output an index of commands

I though of it being something like this:

class AuthCommand extends Command {
  static paths = [[`auth`]]
}

class LoginCommand extends AuthCommand {
  static paths = [[`login`]]

  foo = Option.String(`-f,--foo`)
  async execute() {
    this.context.stdout.write(`This is foo: ${this.foo}.\n`)
  }
}
arcanis commented 1 year ago

paths is an array of arrays, so you can define [['auth', 'login']] and the command will be available as gh auth login.