import "github.com/codegangsta/cli" func main() { app := cli.NewApp() app.Flags = []cli.Flag{ cli.StringFlag{ Name: "name", Usage: "your name", }, } app.Action = func(c *cli.Context) error { name := c.String("name") fmt.Printf("Hello, %s!\n", name) return nil } app.Run(os.Args) }
import "github.com/codegangsta/cli" func main() { app := cli.NewApp() app.Commands = []cli.Command{ { Name: "add", Aliases: []string{"a"}, Usage: "add a task to the list", Action: addTask, }, { Name: "list", Aliases: []string{"l"}, Usage: "list all tasks", Action: listTasks, }, } app.Run(os.Args) } func addTask(c *cli.Context) error { // implementation } func listTasks(c *cli.Context) error { // implementation }In this example, we define two subcommands ("add" and "list") using the `cli.Command` struct, and set their respective `Action` functions. The `*cli.Context` parameter in each of the `Action` functions is used to access any additional arguments or flags that were passed with the subcommand. Overall, the `github.com.codegangsta.cli` package library provides a useful set of tools for building command-line interfaces in Go, with the `Context` struct being a key component for managing state and accessing user input.