mow.cli icon indicating copy to clipboard operation
mow.cli copied to clipboard

Expose a model of the command structure

Open skyzyx opened this issue 5 years ago • 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[]. https://github.com/jawher/mow.cli/blob/fbc50e90e1fb96a3ddde67f9ca6289b8054f2f7e/commands.go#L127-L141

skyzyx avatar Mar 31 '20 18:03 skyzyx

Ping?

skyzyx avatar Jun 11 '20 10:06 skyzyx

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.

jawher avatar Jun 17 '20 08:06 jawher

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!

skyzyx avatar Jun 28 '20 18:06 skyzyx

@skyzyx Thank you for your patience 🤗

I just pushed a branch with a PoC of an app model: https://github.com/jawher/mow.cli/pull/106

I would be grateful if you could play with it and share your feedback.

jawher avatar Jul 03 '20 14:07 jawher

OK. I have some time to play with this today. Any idea how to pull this branch with go.mod?

skyzyx avatar Jul 17 '20 21:07 skyzyx

I have tested this, and it works marvelously. Thank you.

Getting a new tag with this functionality would be appreciated.

skyzyx avatar Jan 15 '21 00:01 skyzyx