import "github.com/codegangsta/cli" func main() { app := cli.NewApp() app.Flags = []cli.Flag{ cli.StringSliceFlag{ Name: "string-slice", Usage: "A slice of string values", }, } app.Action = func(c *cli.Context) error { stringSlice := c.StringSlice("string-slice") for i := range stringSlice { fmt.Println(stringSlice[i]) } return nil } app.Run(os.Args) }
import "github.com/codegangsta/cli" func main() { app := cli.NewApp() app.Flags = []cli.Flag{ cli.StringSliceFlag{ Name: "string-slice", Usage: "A slice of string values", }, } app.Commands = []cli.Command{ { Name: "example", Usage: "An example command", Action: exampleCommand, }, } app.Run(os.Args) } func exampleCommand(c *cli.Context) error { stringSlice := c.StringSlice("string-slice") for i := range stringSlice { fmt.Println(stringSlice[i]) } return nil }In this example, we are using the Context StringSlice to capture a slice of string values from a command line flag (`--string-slice`) in a subcommand (called "example"). We then pass the Context to the `exampleCommand` function, where we can access the string slice and loop over it to print out each value.