From 5325c18c4eb67dbe8320bbd177f931560226aa29 Mon Sep 17 00:00:00 2001 From: Louison SARLIN--MAGNUS Date: Fri, 3 Apr 2026 11:41:42 +0200 Subject: [PATCH] feat: adding progress command --- commands/progress_task.go | 18 ++++++++++++++++++ gotask-cli.go | 16 +++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 commands/progress_task.go diff --git a/commands/progress_task.go b/commands/progress_task.go new file mode 100644 index 0000000..bb2209b --- /dev/null +++ b/commands/progress_task.go @@ -0,0 +1,18 @@ +package commands + +import ( + "fmt" + "gotask-cli/models" + "time" +) + +func ProgressTask(id uint, backlog []models.Task) []models.Task { + if backlog[id].Status >= 0 && backlog[id].Status < 2 { + backlog[id].Status++ + backlog[id].Updated = time.Now().Unix() + fmt.Printf("[%s] task \"%s\" progress to [%s]", models.StatusName[backlog[id].Status-1], backlog[id].Description, models.StatusName[backlog[id].Status]) + } else { + fmt.Printf("Can't progress task %s", backlog[id].Description) + } + return backlog +} diff --git a/gotask-cli.go b/gotask-cli.go index a4219e4..80faa16 100644 --- a/gotask-cli.go +++ b/gotask-cli.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "strconv" "gotask-cli/commands" "gotask-cli/utils" @@ -17,7 +18,7 @@ func main() { case "help": commands.Help() case "add": - if len(os.Args[1:]) >= 2 { + if len(os.Args[1:]) == 2 { backlog = commands.AddTask(os.Args[2], backlog) } else { fmt.Println("Missing argument") @@ -25,6 +26,19 @@ func main() { } case "list": commands.ListTasks(backlog) + case "progress": + if len(os.Args[1:]) == 2 { + id, err := strconv.ParseUint(os.Args[2], 10, 32) + utils.Check(err) + if id > 0 && id <= uint64(len(backlog)) { + commands.ProgressTask(uint(id)-1, backlog) + } else { + fmt.Printf("No task found with id=%d, try list to get id", id) + } + } else { + fmt.Println("Missing argument") + commands.Help() + } default: fmt.Println("NO !") }