From 5fdc04709975732733bf0ddc1308ea25c0cb453a Mon Sep 17 00:00:00 2001 From: demo Date: Fri, 29 May 2026 10:24:27 -0400 Subject: refactor: funnel business logic into bespoke functions This way: 1. We don't have to stuff all our business logic where urfave is set up. 2. Our functions aren't forced to use the signature required by the Action field. --- main.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 6472554..96bbcfc 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "os" + "strings" "github.com/urfave/cli/v3" ) @@ -18,8 +19,10 @@ func main() { 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 + args := cmd.Args().Slice() + task := strings.Join(args, " ") + + return cmdAdd(task) }, }, { @@ -43,8 +46,7 @@ func main() { return fmt.Errorf("invalid 'do' argument: %d", taskIndex) } - fmt.Println("completed task: ", taskIndex) - return nil + return cmdDo(taskIndex) }, }, { @@ -52,8 +54,7 @@ func main() { Aliases: []string{"l"}, Usage: "list pending tasks", Action: func(ctx context.Context, cmd *cli.Command) error { - fmt.Println("listed pending tasks") - return nil + return cmdList() }, }, }, -- cgit v1.2.3