|
|
@ -14,7 +14,7 @@ func ExampleApp() {
|
|
|
|
app := cli.NewApp()
|
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "greet"
|
|
|
|
app.Name = "greet"
|
|
|
|
app.Flags = []cli.Flag{
|
|
|
|
app.Flags = []cli.Flag{
|
|
|
|
cli.StringFlag{"name", "bob", "a name to say"},
|
|
|
|
cli.StringFlag{Name: "name", Value: "bob", Usage: "a name to say"},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
app.Action = func(c *cli.Context) {
|
|
|
|
app.Action = func(c *cli.Context) {
|
|
|
|
fmt.Printf("Hello %v\n", c.String("name"))
|
|
|
|
fmt.Printf("Hello %v\n", c.String("name"))
|
|
|
@ -29,7 +29,7 @@ func TestApp_Run(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
app := cli.NewApp()
|
|
|
|
app := cli.NewApp()
|
|
|
|
app.Action = func(c *cli.Context) {
|
|
|
|
app.Action = func(c *cli.Context) {
|
|
|
|
s = s + c.Args()[0]
|
|
|
|
s = s + c.Args().First()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err := app.Run([]string{"command", "foo"})
|
|
|
|
err := app.Run([]string{"command", "foo"})
|
|
|
@ -72,11 +72,11 @@ func TestApp_CommandWithArgBeforeFlags(t *testing.T) {
|
|
|
|
command := cli.Command{
|
|
|
|
command := cli.Command{
|
|
|
|
Name: "cmd",
|
|
|
|
Name: "cmd",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.StringFlag{"option", "", "some option"},
|
|
|
|
cli.StringFlag{Name: "option", Value: "", Usage: "some option"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(c *cli.Context) {
|
|
|
|
Action: func(c *cli.Context) {
|
|
|
|
parsedOption = c.String("option")
|
|
|
|
parsedOption = c.String("option")
|
|
|
|
firstArg = c.Args()[0]
|
|
|
|
firstArg = c.Args().First()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
app.Commands = []cli.Command{command}
|
|
|
|
app.Commands = []cli.Command{command}
|
|
|
@ -96,14 +96,14 @@ func TestApp_ParseSliceFlags(t *testing.T) {
|
|
|
|
command := cli.Command{
|
|
|
|
command := cli.Command{
|
|
|
|
Name: "cmd",
|
|
|
|
Name: "cmd",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.IntSliceFlag{"p", &cli.IntSlice{}, "set one or more ip addr"},
|
|
|
|
cli.IntSliceFlag{Name: "p", Value: &cli.IntSlice{}, Usage: "set one or more ip addr"},
|
|
|
|
cli.StringSliceFlag{"ip", &cli.StringSlice{}, "set one or more ports to open"},
|
|
|
|
cli.StringSliceFlag{Name: "ip", Value: &cli.StringSlice{}, Usage: "set one or more ports to open"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(c *cli.Context) {
|
|
|
|
Action: func(c *cli.Context) {
|
|
|
|
parsedIntSlice = c.IntSlice("p")
|
|
|
|
parsedIntSlice = c.IntSlice("p")
|
|
|
|
parsedStringSlice = c.StringSlice("ip")
|
|
|
|
parsedStringSlice = c.StringSlice("ip")
|
|
|
|
parsedOption = c.String("option")
|
|
|
|
parsedOption = c.String("option")
|
|
|
|
firstArg = c.Args()[0]
|
|
|
|
firstArg = c.Args().First()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
app.Commands = []cli.Command{command}
|
|
|
|
app.Commands = []cli.Command{command}
|
|
|
|