jwaldrip / admiral.cr

A robust DSL for writing command line interfaces written in Crystal.
https://jwaldrip.github.com/admiral.cr
MIT License
135 stars 14 forks source link

Parent flags/arguments in subcommands help #24

Open EppO opened 4 years ago

EppO commented 4 years ago

Hi,

currently, the help of the subcommands doesn't show the global flags/arguments of the parent. Taking the following example:

equire "admiral"

class ParentCmd < Admiral::Command
  class ChildCmd < Admiral::Command
    define_help description: "Execute a subcommand."

    define_argument childarg : String, description: "Arg for child", required: true

    def run
      puts "in ChildCmd with #{arguments.childarg}"
    end
  end

  register_sub_command child : ChildCmd, "Child Command"

  define_flag parentflag : Bool, description: "Parent flag", default: false, short: p
  define_help description: "Test subcommands help with global flag"

  def run
    puts help
  end
end

ParentCmd.run

I would expect the parentflag to show up in the ChildCmd help page:

$ ./testsub --help
Usage:
  ./testsub [flags...] [arg...]

Test subcommands help with global flag

Flags:
  --help            # Displays help for the current command.
  --parentflag, -p  # Parent flag

Subcommands:
  child             # Execute a subcommand.

$ /testsub child --help 
Usage:
  ./testsub child [flags...] <childarg> [arg...]

Execute a subcommand.

Flags:
  --help               # Displays help for the current command.

Arguments:
  childarg (required)  # Arg for child
jwaldrip commented 4 years ago

I will look into this.

mjblack commented 1 month ago

has there been any effort towards implementing this feature?