Skip to content

Commit 28c16b4

Browse files
committed
docs: use app.run
Signed-off-by: Christian Stewart <christian@aperture.us>
1 parent a099ff8 commit 28c16b4

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ package main
3434

3535
import (
3636
"fmt"
37+
"log"
3738
"os"
3839

3940
"github.com/aperturerobotics/cli"
4041
)
4142

4243
func main() {
43-
cmd := &cli.Command{
44+
app := &cli.App{
4445
Name: "greet",
45-
Usage: "say hello",
46+
Usage: "a simple greeter application",
4647
Flags: []cli.Flag{
4748
&cli.StringFlag{
4849
Name: "name",
@@ -51,15 +52,18 @@ func main() {
5152
EnvVars: []string{"GREET_NAME"},
5253
},
5354
},
55+
// The action for the root command (optional)
5456
Action: func(ctx *cli.Context) error {
5557
name := ctx.String("name")
5658
fmt.Printf("Hello %s!\n", name)
5759
return nil
5860
},
59-
Subcommands: []*cli.Command{
61+
// Define subcommands
62+
Commands: []*cli.Command{
6063
{
6164
Name: "add",
6265
Usage: "add a task to the list",
66+
// Action for the 'add' subcommand
6367
Action: func(ctx *cli.Context) error {
6468
fmt.Println("added task: ", ctx.Args().First())
6569
return nil
@@ -68,6 +72,7 @@ func main() {
6872
{
6973
Name: "complete",
7074
Usage: "complete a task on the list",
75+
// Action for the 'complete' subcommand
7176
Action: func(ctx *cli.Context) error {
7277
fmt.Println("completed task: ", ctx.Args().First())
7378
return nil
@@ -76,9 +81,9 @@ func main() {
7681
},
7782
}
7883

79-
if err := cmd.Run(os.Args); err != nil {
80-
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
81-
os.Exit(1)
84+
// Run the application
85+
if err := app.Run(os.Args); err != nil {
86+
log.Fatal(err)
8287
}
8388
}
8489

docs/index.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ package main
2828

2929
import (
3030
"fmt"
31+
"log"
3132
"os"
3233

3334
"github.com/aperturerobotics/cli"
3435
)
3536

3637
func main() {
37-
cmd := &cli.Command{
38+
app := &cli.App{
3839
Name: "greet",
39-
Usage: "say hello",
40+
Usage: "a simple greeter application",
4041
Flags: []cli.Flag{
4142
&cli.StringFlag{
4243
Name: "name",
@@ -45,15 +46,18 @@ func main() {
4546
EnvVars: []string{"GREET_NAME"},
4647
},
4748
},
49+
// The action for the root command (optional)
4850
Action: func(ctx *cli.Context) error {
4951
name := ctx.String("name")
5052
fmt.Printf("Hello %s!\n", name)
5153
return nil
5254
},
53-
Subcommands: []*cli.Command{
55+
// Define subcommands
56+
Commands: []*cli.Command{
5457
{
5558
Name: "add",
5659
Usage: "add a task to the list",
60+
// Action for the 'add' subcommand
5761
Action: func(ctx *cli.Context) error {
5862
fmt.Println("added task: ", ctx.Args().First())
5963
return nil
@@ -62,6 +66,7 @@ func main() {
6266
{
6367
Name: "complete",
6468
Usage: "complete a task on the list",
69+
// Action for the 'complete' subcommand
6570
Action: func(ctx *cli.Context) error {
6671
fmt.Println("completed task: ", ctx.Args().First())
6772
return nil
@@ -70,9 +75,9 @@ func main() {
7075
},
7176
}
7277

73-
if err := cmd.Run(os.Args); err != nil {
74-
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
75-
os.Exit(1)
78+
// Run the application
79+
if err := app.Run(os.Args); err != nil {
80+
log.Fatal(err)
7681
}
7782
}
7883
```

0 commit comments

Comments
 (0)