Skip to content

Expose a model of the command structure #104

@skyzyx

Description

@skyzyx

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{},
})
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions