Allow to sort commands by category

This commit is contained in:
Soulou
2014-12-15 23:35:49 +01:00
committed by Jesse Szwedko
parent aca5b047ed
commit a0801792cc
3 changed files with 25 additions and 4 deletions

View File

@@ -22,6 +22,8 @@ type Command struct {
Description string
// A short description of the arguments of this command
ArgsUsage string
// The category the command is part of
Category string
// The function to call when checking for bash command completions
BashComplete func(context *Context)
// An action to execute before any sub-subcommands are run, but after the context is ready
@@ -37,7 +39,7 @@ type Command struct {
// If this function is not set, the "Incorrect usage" is displayed and the execution is interrupted.
OnUsageError func(context *Context, err error) error
// List of child commands
Subcommands []Command
Subcommands Commands
// List of flags to parse
Flags []Flag
// Treat all flags as normal arguments if true
@@ -59,6 +61,8 @@ func (c Command) FullName() string {
return strings.Join(c.commandNamePath, " ")
}
type Commands []Command
// Invokes the command given the context, parses ctx.Args() to generate command-specific flags
func (c Command) Run(ctx *Context) (err error) {
if len(c.Subcommands) > 0 {