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
56
57
58
59
60
61
62
63
64
65
66
|
package main
import (
"context"
"fmt"
"log"
"os"
"strings"
"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 {
args := cmd.Args().Slice()
task := strings.Join(args, " ")
return cmdAdd(task)
},
},
{
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")
// If taskIndex is 0, it's
// likely missing; any other
// non-positive value is a
// deliberate
// misconfiguration.
if taskIndex <= 0 {
return fmt.Errorf("invalid 'do' argument: %d", taskIndex)
}
return cmdDo(taskIndex)
},
},
{
Name: "list",
Aliases: []string{"l"},
Usage: "list pending tasks",
Action: func(ctx context.Context, cmd *cli.Command) error {
return cmdList()
},
},
},
}
if err := cmd.Run(context.Background(), os.Args); err != nil {
log.Fatal(err)
}
}
|