Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose a model of the command structure #104

Open
skyzyx opened this issue Mar 31, 2020 · 6 comments · May be fixed by #106
Open

Expose a model of the command structure #104

skyzyx opened this issue Mar 31, 2020 · 6 comments · May be fixed by #106

Comments

@skyzyx
Copy link

skyzyx commented Mar 31, 2020

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[].

mow.cli/commands.go

Lines 127 to 141 in fbc50e9

func (c *Cmd) Command(name, desc string, init CmdInitializer) {
aliases := strings.Fields(name)
c.commands = append(c.commands, &Cmd{
ErrorHandling: c.ErrorHandling,
name: aliases[0],
aliases: aliases,
desc: desc,
init: init,
commands: []*Cmd{},
options: []*container.Container{},
optionsIdx: map[string]*container.Container{},
args: []*container.Container{},
argsIdx: map[string]*container.Container{},
})
}

@skyzyx
Copy link
Author

skyzyx commented Jun 11, 2020

Ping?

@jawher
Copy link
Owner

jawher commented Jun 17, 2020

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.

@skyzyx
Copy link
Author

skyzyx commented Jun 28, 2020

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!

jawher added a commit that referenced this issue Jul 3, 2020
`app.Model()`

Fixes #104
@jawher jawher linked a pull request Jul 3, 2020 that will close this issue
@jawher
Copy link
Owner

jawher commented Jul 3, 2020

@skyzyx Thank you for your patience 🤗

I just pushed a branch with a PoC of an app model: #106

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

@skyzyx
Copy link
Author

skyzyx commented Jul 17, 2020

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

@skyzyx
Copy link
Author

skyzyx commented Jan 15, 2021

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

Getting a new tag with this functionality would be appreciated.

mewil pushed a commit to mewil/mow.cli that referenced this issue Jan 16, 2021
`app.Model()`

Fixes jawher#104
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants