package main import ( "fmt" "github.com/micro/cli" ) func main() { app := cli.NewApp() app.Name = "myapp" app.Usage = "myapp does things" app.Action = func(c *cli.Context) error { fmt.Println("Hello from myapp!") return nil } app.Run(os.Args) }
package main import ( "fmt" "github.com/micro/cli" ) func main() { app := cli.NewApp() app.Name = "myapp" app.Usage = "myapp does things" app.Commands = []cli.Command{ { Name: "greeting", Aliases: []string{"g"}, Usage: "say hello", Flags: []cli.Flag{ cli.StringFlag{ Name: "name", Usage: "your name", }, }, Action: func(c *cli.Context) error { name := c.String("name") fmt.Printf("Hello, %s!\n", name) return nil }, }, } app.Run(os.Args) }
package main import ( "fmt" "github.com/micro/cli" ) func main() { app := cli.NewApp() app.Name = "myapp" app.Usage = "myapp does things" app.Flags = []cli.Flag{ cli.BoolFlag{ Name: "verbose", Usage: "verbose output", }, } app.Action = func(c *cli.Context) error { if c.Bool("verbose") { fmt.Println("Verbose is on!") } fmt.Println("Hello from myapp!") return nil } app.Run(os.Args) }This example adds a global `--verbose` flag to the app, which can be used to turn on verbose output. The `cli.BoolFlag` type is used to define the flag, and the app's `app.Action` callback function checks the flag to determine whether to print the "Verbose is on!" message.