commander-rb / commander

The complete solution for Ruby command-line executables
MIT License
822 stars 74 forks source link

Use --help after command and argument #95

Closed orien closed 4 years ago

orien commented 4 years ago

Context

It is reported in #94 that using --help after a command name and command argument does not work.

$ mycli command-name command-arg --help
invalid command. Use --help for more information

Investigation finds the help command is assuming the the command name is all the arguments joined together.

https://github.com/commander-rb/commander/blob/b8abd42153118ca9fdc02affeb9f3aab61cda5a2/lib/commander/runner.rb#L307

Change

Fix #94 by changing the line in question to ignore the command argument when searching for command name. Just take the longest valid command name found in the arguments.

Considerations

This also changes the behaviour of the help command in its alternate form. This will ignore the argument and provide the documentation for the specified command, where previously it would give an error message.

mycli help command-name command-arg