|
|
@ -29,41 +29,24 @@ func ExampleApp() {
|
|
|
|
// Hello Jeremy
|
|
|
|
// Hello Jeremy
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func ExampleAppSubcommand() {
|
|
|
|
func ExampleAppCommands() {
|
|
|
|
// set args for examples sake
|
|
|
|
// set args for examples sake
|
|
|
|
os.Args = []string{"say", "hi", "english", "--name", "Jeremy"}
|
|
|
|
os.Args = []string{"greet", "--name", "Jeremy"}
|
|
|
|
|
|
|
|
|
|
|
|
app := cli.NewApp()
|
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "say"
|
|
|
|
app.Name = "greet"
|
|
|
|
app.Commands = []cli.Command{
|
|
|
|
app.Flags = []cli.Flag{
|
|
|
|
{
|
|
|
|
cli.StringFlag{Name: "name", Value: "bob", Usage: "a name to say"},
|
|
|
|
Name: "hello",
|
|
|
|
|
|
|
|
ShortName: "hi",
|
|
|
|
|
|
|
|
Usage: "use it to see a description",
|
|
|
|
|
|
|
|
Description: "This is how we describe hello the function",
|
|
|
|
|
|
|
|
Subcommands: []cli.Command{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Name: "english",
|
|
|
|
|
|
|
|
ShortName: "en",
|
|
|
|
|
|
|
|
Usage: "sends a greeting in english",
|
|
|
|
|
|
|
|
Description: "greets someone in english",
|
|
|
|
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
|
|
|
|
cli.StringFlag{
|
|
|
|
|
|
|
|
Name: "name",
|
|
|
|
|
|
|
|
Value: "Bob",
|
|
|
|
|
|
|
|
Usage: "Name of the person to greet",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Action: func(c *cli.Context) {
|
|
|
|
|
|
|
|
fmt.Println("Hello,", c.String("name"))
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
app.Action = func(c *cli.Context) {
|
|
|
|
|
|
|
|
fmt.Printf("Hello %v\n", c.String("name"))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
app.Author = "Harrison"
|
|
|
|
|
|
|
|
app.Email = "harrison@lolwut.com"
|
|
|
|
|
|
|
|
app.Authors = []cli.Author{{"Oliver Allen", "oliver@toyshop.com"}}
|
|
|
|
app.Run(os.Args)
|
|
|
|
app.Run(os.Args)
|
|
|
|
// Output:
|
|
|
|
// Output:
|
|
|
|
// Hello, Jeremy
|
|
|
|
// Hello Jeremy
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func ExampleAppHelp() {
|
|
|
|
func ExampleAppHelp() {
|
|
|
@ -78,7 +61,7 @@ func ExampleAppHelp() {
|
|
|
|
app.Commands = []cli.Command{
|
|
|
|
app.Commands = []cli.Command{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Name: "describeit",
|
|
|
|
Name: "describeit",
|
|
|
|
ShortName: "d",
|
|
|
|
Aliases: []string{"d"},
|
|
|
|
Usage: "use it to see a description",
|
|
|
|
Usage: "use it to see a description",
|
|
|
|
Description: "This is how we describe describeit the function",
|
|
|
|
Description: "This is how we describe describeit the function",
|
|
|
|
Action: func(c *cli.Context) {
|
|
|
|
Action: func(c *cli.Context) {
|
|
|
@ -108,7 +91,7 @@ func ExampleAppBashComplete() {
|
|
|
|
app.Commands = []cli.Command{
|
|
|
|
app.Commands = []cli.Command{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Name: "describeit",
|
|
|
|
Name: "describeit",
|
|
|
|
ShortName: "d",
|
|
|
|
Aliases: []string{"d"},
|
|
|
|
Usage: "use it to see a description",
|
|
|
|
Usage: "use it to see a description",
|
|
|
|
Description: "This is how we describe describeit the function",
|
|
|
|
Description: "This is how we describe describeit the function",
|
|
|
|
Action: func(c *cli.Context) {
|
|
|
|
Action: func(c *cli.Context) {
|
|
|
@ -162,8 +145,8 @@ var commandAppTests = []struct {
|
|
|
|
|
|
|
|
|
|
|
|
func TestApp_Command(t *testing.T) {
|
|
|
|
func TestApp_Command(t *testing.T) {
|
|
|
|
app := cli.NewApp()
|
|
|
|
app := cli.NewApp()
|
|
|
|
fooCommand := cli.Command{Name: "foobar", ShortName: "f"}
|
|
|
|
fooCommand := cli.Command{Name: "foobar", Aliases: []string{"f"}}
|
|
|
|
batCommand := cli.Command{Name: "batbaz", ShortName: "b"}
|
|
|
|
batCommand := cli.Command{Name: "batbaz", Aliases: []string{"b"}}
|
|
|
|
app.Commands = []cli.Command{
|
|
|
|
app.Commands = []cli.Command{
|
|
|
|
fooCommand,
|
|
|
|
fooCommand,
|
|
|
|
batCommand,
|
|
|
|
batCommand,
|
|
|
|