Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First off, thank you so much for GLI. I'm a huge fan ❤️
I'd like to propose adding a new hook called
command_missing
which works much like Ruby'smethod_missing
method.command_missing
is called whenever a top-level command can't be found, and expects the block it captures to return an instance ofGLI::Command
.I'm the author of the Kuby project, a tool for deploying Rails apps. Kuby features a plugin system, and therein lies my use-case. I would like plugins to have the ability to specify their own sets of commands, eg.
kuby plugin_name plugin_subcommand ...
The problem is that the list of plugins isn't known until the config file is loaded, which happens in a GLIpre
hook. I need to be able to defer defining commands until the config file has been loaded, but before all the CLI options have been parsed. With the changes in this PR, the following is now possible:One of the key changes here is that the
command
method now returns the command object, and since that's the last line of thecommand_missing
block, it gets returned to the parser. It's a bit funky to be sure, but it works.Let me know what you think!