diff --git a/commands/regress_task.go b/commands/regress_task.go new file mode 100644 index 0000000..b8c941c --- /dev/null +++ b/commands/regress_task.go @@ -0,0 +1,18 @@ +package commands + +import ( + "fmt" + "gotask-cli/models" + "time" +) + +func RegressTask(id uint, backlog []models.Task) []models.Task { + if backlog[id].Status >= 1 && backlog[id].Status <= 2 { + backlog[id].Status-- + backlog[id].Updated = time.Now().Unix() + fmt.Printf("[%s] task \"%s\" regress to [%s]", models.StatusName[backlog[id].Status+1], backlog[id].Description, models.StatusName[backlog[id].Status]) + } else { + fmt.Printf("Can't regress task %s", backlog[id].Description) + } + return backlog +} diff --git a/gotask-cli.go b/gotask-cli.go index 80faa16..828d26e 100644 --- a/gotask-cli.go +++ b/gotask-cli.go @@ -39,6 +39,19 @@ func main() { fmt.Println("Missing argument") commands.Help() } + case "regress": + 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.RegressTask(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 !") }