|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "log" |
| 7 | + "os" |
| 8 | + |
| 9 | + "github.com/urfave/cli/v3" |
| 10 | +) |
| 11 | + |
| 12 | +func main() { |
| 13 | + cmd := &cli.Command{ |
| 14 | + Name: "greet", |
| 15 | + EnableShellCompletion: true, |
| 16 | + Commands: []*cli.Command{ |
| 17 | + { |
| 18 | + Name: "add", |
| 19 | + Aliases: []string{"a"}, |
| 20 | + Usage: "add a task to the list", |
| 21 | + Action: func(ctx context.Context, cmd *cli.Command) error { |
| 22 | + fmt.Println("added task: ", cmd.Args().First()) |
| 23 | + return nil |
| 24 | + }, |
| 25 | + }, |
| 26 | + { |
| 27 | + Name: "complete", |
| 28 | + Aliases: []string{"c"}, |
| 29 | + Usage: "complete a task on the list", |
| 30 | + Action: func(ctx context.Context, cmd *cli.Command) error { |
| 31 | + fmt.Println("completed task: ", cmd.Args().First()) |
| 32 | + return nil |
| 33 | + }, |
| 34 | + }, |
| 35 | + { |
| 36 | + Name: "template", |
| 37 | + Aliases: []string{"t"}, |
| 38 | + Usage: "options for task templates", |
| 39 | + Commands: []*cli.Command{ |
| 40 | + { |
| 41 | + Name: "add", |
| 42 | + Usage: "add a new template", |
| 43 | + Action: func(ctx context.Context, cmd *cli.Command) error { |
| 44 | + fmt.Println("new task template: ", cmd.Args().First()) |
| 45 | + return nil |
| 46 | + }, |
| 47 | + }, |
| 48 | + { |
| 49 | + Name: "remove", |
| 50 | + Usage: "remove an existing template", |
| 51 | + Action: func(ctx context.Context, cmd *cli.Command) error { |
| 52 | + fmt.Println("removed task template: ", cmd.Args().First()) |
| 53 | + return nil |
| 54 | + }, |
| 55 | + }, |
| 56 | + }, |
| 57 | + }, |
| 58 | + }, |
| 59 | + } |
| 60 | + |
| 61 | + if err := cmd.Run(context.Background(), os.Args); err != nil { |
| 62 | + log.Fatal(err) |
| 63 | + } |
| 64 | +} |
0 commit comments