From b6745b7bbe53678e00f4876234ff08b353c7c34c Mon Sep 17 00:00:00 2001 From: demo Date: Thu, 28 May 2026 22:21:29 -0400 Subject: feat: implement stub of task CLI app Now it's for real, no more preliminary examples. --- main.go | 64 +++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 31 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 079ccc5..26bbce2 100644 --- a/main.go +++ b/main.go @@ -5,45 +5,47 @@ import ( "fmt" "log" "os" - "strings" "github.com/urfave/cli/v3" ) func main() { cmd := &cli.Command{ - Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "lang", - Value: "en", - Usage: "language used for the greeting", + 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 + }, }, - &cli.IntFlag{ - Name: "times", - Value: 1, - Usage: "number of times to repeat word for hello", + { + 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 + }, }, - }, - Usage: "top level application", - Action: func(ctx context.Context, cmd *cli.Command) error { - name := "Brandon" - if cmd.NArg() > 0 { - name = cmd.Args().First() - } - - dir := map[string]string{ - "es": "Hola", - "en": "Hello", - } - - greeting, ok := dir[cmd.String("lang")] - if !ok { - greeting = "???" - } - - fmt.Printf("%s, %s\n", strings.Repeat(greeting, cmd.Int("times")), name) - - return nil }, } -- cgit v1.2.3