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) } }