feat: adding progress command
This commit is contained in:
18
commands/progress_task.go
Normal file
18
commands/progress_task.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"gotask-cli/commands"
|
"gotask-cli/commands"
|
||||||
"gotask-cli/utils"
|
"gotask-cli/utils"
|
||||||
@@ -17,7 +18,7 @@ func main() {
|
|||||||
case "help":
|
case "help":
|
||||||
commands.Help()
|
commands.Help()
|
||||||
case "add":
|
case "add":
|
||||||
if len(os.Args[1:]) >= 2 {
|
if len(os.Args[1:]) == 2 {
|
||||||
backlog = commands.AddTask(os.Args[2], backlog)
|
backlog = commands.AddTask(os.Args[2], backlog)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Missing argument")
|
fmt.Println("Missing argument")
|
||||||
@@ -25,6 +26,19 @@ func main() {
|
|||||||
}
|
}
|
||||||
case "list":
|
case "list":
|
||||||
commands.ListTasks(backlog)
|
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:
|
default:
|
||||||
fmt.Println("NO !")
|
fmt.Println("NO !")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user