summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmds.go20
-rw-r--r--main.go13
2 files changed, 27 insertions, 6 deletions
diff --git a/cmds.go b/cmds.go
new file mode 100644
index 0000000..26cded5
--- /dev/null
+++ b/cmds.go
@@ -0,0 +1,20 @@
+package main
+
+import (
+ "fmt"
+)
+
+func cmdAdd(task string) error {
+ fmt.Println("added task: ", task)
+ return nil
+}
+
+func cmdDo(taskIndex int) error {
+ fmt.Println("completed task: ", taskIndex)
+ return nil
+}
+
+func cmdList() error {
+ fmt.Println("listed pending tasks")
+ return nil
+}
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()
},
},
},