Closed camertron closed 2 years ago
Hey, thanks for the PR. Quick scan it looks good. Did you know about commands_from
? It's a glorified require
but that was added to allow GLI commands to have plugins. Though I guess if it's not run when the app loads it may not work? Can you see if that would work for your use case? If not, I'll give this a more detailed review
@davetron5000 oh cool I didn't know about commands_from
😄 I took a look at the docs and unfortunately I don't think it covers my use-case. Part of my particular problem is that load_kuby_config!
depends on the global_options
hash (because it contains the path to the Kuby config file), which AFAIK isn't available until GLI::GlobalOptionParser
is finished doing its thing.
I also tried adding the commands inside the pre
hook, but it looks like commands have to exist before pre
is called.
OK, sounds good. Like I said, this looks great, so gonna merge and do a realease real quick
Released as 2.21.0. Thanks!
Sweet, thank you!
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!