app := cli.NewApp() app.Flags = []cli.Flag{ cli.BoolFlag{ Name: "verbose", Usage: "print verbose output", EnvVar: "MY_APP_VERBOSE", }, } app.Commands = []cli.Command{ { Name: "run", Usage: "run the command", Flags: []cli.Flag{ cli.BoolFlag{ Name: "force", Usage: "force the command to run", }, }, Action: func(c *cli.Context) error { if c.GlobalBool("verbose") { fmt.Println("Running in verbose mode") } if c.Bool("force") { fmt.Println("Forcing run") } fmt.Println("Running command") return nil }, }, } app.Run(os.Args)In this example, the CLI has a global flag called `verbose`, which can be set to true or false via an environment variable. The `run` command also has its own flag called `force`, which can be set to true or false. The `Action` function of the `run` command checks for the value of the global `verbose` flag and the local `force` flag before executing the command. Overall, the `github.com/codegangsta/cli` package is a powerful and flexible library for building CLI applications in Go.