-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Description
With example code:
package main
import (
"fmt"
"os"
"gopkg.in/urfave/cli.v2"
)
func main() {
app := &cli.App{
Commands: []*cli.Command{
{
Name: "add",
Aliases: []string{"a"},
Usage: "add a task to the list",
Action: func(c *cli.Context) error {
fmt.Println("added task: ", c.Args().First())
return nil
},
},
{
Name: "complete",
Aliases: []string{"c"},
Usage: "complete a task on the list",
Action: func(c *cli.Context) error {
fmt.Println("completed task: ", c.Args().First())
return nil
},
},
{
Name: "template",
Aliases: []string{"t"},
Usage: "options for task templates",
Subcommands: []*cli.Command{
{
Name: "add",
Usage: "add a new template",
Action: func(c *cli.Context) error {
fmt.Println("new task template: ", c.Args().First())
return nil
},
},
{
Name: "remove",
Usage: "remove an existing template",
Action: func(c *cli.Context) error {
fmt.Println("removed task template: ", c.Args().First())
return nil
},
},
},
},
},
}
app.Run(os.Args)
}gives
$ go run scratch.go help template
NAME:
scratch template - options for task templates
USAGE:
scratch template [arguments...]
Whereas this shows the subcommands
NAME:
scratch template - options for task templates
USAGE:
scratch template [global options] command [command options] [arguments...]
VERSION:
0.0.0
COMMANDS:
add add a new template
remove remove an existing template
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help (default: false)
--version, -v print the version (default: false)
Output should be the same in both cases imo
edit: lol, not sure what the second command is supposed to be. probably --help flag.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels