summaryrefslogtreecommitdiff
path: root/main.go
blob: 26bbce23638916ca91cd80f999ea3c71dd069d19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/urfave/cli/v3"
)

func main() {
	cmd := &cli.Command{
		Commands: []*cli.Command{
			{

				Name:    "add",
				Aliases: []string{"a"},
				Usage:   "add a task to the list",
				Action: func(ctx context.Context, cmd *cli.Command) error {
					fmt.Println("added task: ", cmd.Args().Slice())
					return nil
				},
			},
			{
				Name:    "do",
				Aliases: []string{"d"},
				Usage:   "complete a task on the list",
				Arguments: []cli.Argument{
					&cli.IntArg{
						Name: "taskIndex",
					},
				},
				Action: func(ctx context.Context, cmd *cli.Command) error {
					taskIndex := cmd.IntArg("taskIndex")
					fmt.Println("completed task: ", taskIndex)
					return nil
				},
			},
			{
				Name:    "list",
				Aliases: []string{"l"},
				Usage:   "list pending tasks",
				Action: func(ctx context.Context, cmd *cli.Command) error {
					fmt.Println("listed pending tasks")
					return nil
				},
			},
		},
	}

	if err := cmd.Run(context.Background(), os.Args); err != nil {
		log.Fatal(err)
	}
}