app := cli.NewApp() app.Commands = []cli.Command{ { Name: "my-command", Usage: "Example command with optional StringSlice argument", Flags: []cli.Flag{ &cli.StringSliceFlag{ Name: "my-strings", Usage: "Optional string slice argument", Required: false, }, }, Action: func(c *cli.Context) error { myStrings := c.StringSlice("my-strings") for _, s := range myStrings { fmt.Printf("String: %s\n", s) } return nil }, }, } err := app.Run(os.Args) if err != nil { log.Fatal(err) }
String: foo String: bar String: bazThe StringSlice type is just one of many utility types and functions included in the github.com/urfave/cli package to support building powerful and flexible command line applications in Go.