Expose a model of the command structure
skyzyx opened this issue · 6 comments
It's easy to build out a command structure to get a CLI app up and going fairly quickly (thank you!).
That said, once I've modeled the command structure in code, I'd like to be able to access a representation of what's been set up. Something that exposes the command structure (possibly as a set of nested structs?).
My end goal is to be able to take this exposed model and do things like generate Bash/Zsh/Fish/Powershell auto-completion scripts. By opening this up, it would make it easier for other packages to integrate features of this type.
I haven't yet dug into the code enough to fully understand the internals, but it looks like it would start with exposing the model for Cmd.commands[]
.
Lines 127 to 141 in fbc50e9
Ping?
Hi 👋
Sorry for the delay.
I'm playing with different options to expose the CLI's structure (commands, options, arguments) without trying it to the internal data structures.
I'll hopefull have a PoC soon in a separate branch if you are willing to test it before merging it.
The idea would be to have a new package, model
for example which contains several structs (Command
, Option
, Argument
) representing a CLI, and have a method to return this representation from the App
struct.
This would be great.
My end goal is to be able to take this exposed model and do things like generate Bash/Zsh/Fish/Powershell auto-completion scripts. By opening this up, it would make it easier for other packages to integrate features of this type.
In the interim, I've ended up having to duplicate the command structure I'm using for this CLI framework, then hard-code what the responses should be. I think that by exposing the structure of the model, it will become dramatically simpler (and more DRY) to respond to <command><TAB>
with the right subcommands and flags.
Thank you!
OK. I have some time to play with this today. Any idea how to pull this branch with go.mod
?
I have tested this, and it works marvelously. Thank you.
Getting a new tag with this functionality would be appreciated.