2013-07-20 22:50:13 +00:00
|
|
|
package cli_test
|
2013-07-19 00:29:06 +00:00
|
|
|
|
|
|
|
import (
|
2013-07-20 22:50:13 +00:00
|
|
|
"os"
|
2014-07-11 22:16:19 +00:00
|
|
|
|
|
|
|
"github.com/codegangsta/cli"
|
2013-07-19 00:29:06 +00:00
|
|
|
)
|
|
|
|
|
2013-07-20 22:50:13 +00:00
|
|
|
func Example() {
|
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "todo"
|
|
|
|
app.Usage = "task list on the command line"
|
|
|
|
app.Commands = []cli.Command{
|
2013-07-19 02:17:33 +00:00
|
|
|
{
|
2015-03-10 04:24:57 +00:00
|
|
|
Name: "add",
|
|
|
|
Aliases: []string{"a"},
|
|
|
|
Usage: "add a task to the list",
|
2013-07-20 22:50:13 +00:00
|
|
|
Action: func(c *cli.Context) {
|
2013-11-24 13:40:21 +00:00
|
|
|
println("added task: ", c.Args().First())
|
2013-07-19 02:17:33 +00:00
|
|
|
},
|
2013-07-20 22:50:13 +00:00
|
|
|
},
|
|
|
|
{
|
2015-03-10 04:24:57 +00:00
|
|
|
Name: "complete",
|
|
|
|
Aliases: []string{"c"},
|
|
|
|
Usage: "complete a task on the list",
|
2013-07-20 22:50:13 +00:00
|
|
|
Action: func(c *cli.Context) {
|
2013-11-24 13:40:21 +00:00
|
|
|
println("completed task: ", c.Args().First())
|
2013-07-19 02:17:33 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2013-07-19 00:29:06 +00:00
|
|
|
|
2013-07-20 22:50:13 +00:00
|
|
|
app.Run(os.Args)
|
2013-07-19 00:29:06 +00:00
|
|
|
}
|
2014-04-16 17:59:34 +00:00
|
|
|
|
|
|
|
func ExampleSubcommand() {
|
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "say"
|
|
|
|
app.Commands = []cli.Command{
|
|
|
|
{
|
|
|
|
Name: "hello",
|
2015-03-10 04:24:57 +00:00
|
|
|
Aliases: []string{"hi"},
|
2014-04-16 17:59:34 +00:00
|
|
|
Usage: "use it to see a description",
|
|
|
|
Description: "This is how we describe hello the function",
|
|
|
|
Subcommands: []cli.Command{
|
|
|
|
{
|
|
|
|
Name: "english",
|
2015-03-10 04:24:57 +00:00
|
|
|
Aliases: []string{"en"},
|
2014-04-16 17:59:34 +00:00
|
|
|
Usage: "sends a greeting in english",
|
|
|
|
Description: "greets someone in english",
|
|
|
|
Flags: []cli.Flag{
|
2014-07-11 22:13:10 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "name",
|
|
|
|
Value: "Bob",
|
|
|
|
Usage: "Name of the person to greet",
|
|
|
|
},
|
2014-04-16 17:59:34 +00:00
|
|
|
},
|
|
|
|
Action: func(c *cli.Context) {
|
|
|
|
println("Hello, ", c.String("name"))
|
|
|
|
},
|
|
|
|
}, {
|
2015-03-10 04:24:57 +00:00
|
|
|
Name: "spanish",
|
|
|
|
Aliases: []string{"sp"},
|
|
|
|
Usage: "sends a greeting in spanish",
|
2014-04-16 17:59:34 +00:00
|
|
|
Flags: []cli.Flag{
|
2014-07-11 22:13:10 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "surname",
|
|
|
|
Value: "Jones",
|
|
|
|
Usage: "Surname of the person to greet",
|
|
|
|
},
|
2014-04-16 17:59:34 +00:00
|
|
|
},
|
|
|
|
Action: func(c *cli.Context) {
|
|
|
|
println("Hola, ", c.String("surname"))
|
|
|
|
},
|
|
|
|
}, {
|
2015-03-10 04:24:57 +00:00
|
|
|
Name: "french",
|
|
|
|
Aliases: []string{"fr"},
|
|
|
|
Usage: "sends a greeting in french",
|
2014-04-16 17:59:34 +00:00
|
|
|
Flags: []cli.Flag{
|
2014-07-11 22:13:10 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "nickname",
|
|
|
|
Value: "Stevie",
|
|
|
|
Usage: "Nickname of the person to greet",
|
|
|
|
},
|
2014-04-16 17:59:34 +00:00
|
|
|
},
|
|
|
|
Action: func(c *cli.Context) {
|
|
|
|
println("Bonjour, ", c.String("nickname"))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
Name: "bye",
|
|
|
|
Usage: "says goodbye",
|
|
|
|
Action: func(c *cli.Context) {
|
|
|
|
println("bye")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
app.Run(os.Args)
|
|
|
|
}
|