command icon indicating copy to clipboard operation
command copied to clipboard

added a Commander to allow sub command nesting.

Open ericaro opened this issue 10 years ago • 0 comments

The main interface is unchanged, but it is now possible to nest subcommands.

a nested subcommand is also a Cmd,

this package provides a help object "Commander", that you can use to write your own Cmd with nested subcommands.

for example

type myCmd struct { // anonymous field to use Commander.Run() method command.Commander }

func (cmd *myCmd) Flags(fs *flag.FlagSet) *flag.FlagSet { // to make a nested command, just build a new commander cmd.Commander = command.NewCommander("ci", fs) // and call the same methods as the usual top level ones cmd.On("log", "print remote log", &cicmd.LogCmd{}, nil) return fs }

to avoid duplicating the code, I've also replaced the top level On, Parse, and Run() function to use a Commander.

And I've also updated the Usage() to print subcommand in alphabetical order.

ericaro avatar Feb 08 '15 15:02 ericaro