import ( "fmt" "os" "github.com/codegangsta/cli" ) func main() { app := cli.NewApp() app.Flags = []cli.Flag { cli.BoolFlag{ Name: "verbose", Usage: "verbose output", }, } app.Action = func(c *cli.Context) { verbose := c.Bool("verbose") if verbose { fmt.Println("Verbose output enabled") } else { fmt.Println("Verbose output disabled") } } err := app.Run(os.Args) if err != nil { fmt.Println(err) } }
import ( "fmt" "os" "github.com/codegangsta/cli" ) func main() { app := cli.NewApp() app.Commands = []cli.Command { { Name: "start", Usage: "start the server", Flags: []cli.Flag { cli.BoolFlag{ Name: "debug", Usage: "enable debugging", }, }, Action: func(c *cli.Context) { debug := c.Bool("debug") if debug { fmt.Println("Starting server in debug mode") } else { fmt.Println("Starting server") } }, }, } err := app.Run(os.Args) if err != nil { fmt.Println(err) } }This example shows how to create a CLI app with a subcommand for starting a server, and a boolean flag for enabling debugging mode. When run with the subcommand and flag, the app will display whether or not debugging mode is enabled based on the provided flag.