feat: adding list_by command

This commit is contained in:
2026-04-03 15:23:58 +02:00
parent 10aabc8c0a
commit 12de0f1b6c
3 changed files with 46 additions and 5 deletions

28
commands/list_tasks_by.go Normal file
View File

@@ -0,0 +1,28 @@
package commands
import (
"fmt"
"gotask-cli/models"
"gotask-cli/utils"
)
func ListTasksBy(status string, backlog []models.Task) {
var backlogToDisplay []models.Task
var statusID models.Status
for i, v := range models.StatusName {
if v == status {
statusID = i
}
}
for _, v := range backlog {
if v.Status == models.Status(statusID) {
backlogToDisplay = append(backlogToDisplay, v)
}
}
if len(backlogToDisplay) > 0 {
utils.PrintTasksAsATable(backlogToDisplay)
} else {
fmt.Printf("No tasks with the status [%s]", status)
}
}

View File

@@ -25,7 +25,20 @@ func main() {
commands.Help() commands.Help()
} }
case "list": case "list":
switch len(os.Args[1:]) {
case 1:
commands.ListTasks(backlog) commands.ListTasks(backlog)
case 2:
switch os.Args[2] {
case "todo", "doing", "done":
commands.ListTasksBy(os.Args[2], backlog)
default:
fmt.Printf("Unknown status %s", os.Args[2])
}
default:
fmt.Println("Too many arguments !")
}
case "progress": case "progress":
if len(os.Args[1:]) == 2 { if len(os.Args[1:]) == 2 {
id, err := strconv.ParseUint(os.Args[2], 10, 32) id, err := strconv.ParseUint(os.Args[2], 10, 32)

View File

@@ -1,14 +1,14 @@
package models package models
type status int type Status int
const ( const (
todo status = iota todo Status = iota
doing doing
done done
) )
var StatusName = map[status]string{ var StatusName = map[Status]string{
todo: "todo", todo: "todo",
doing: "doing", doing: "doing",
done: "done", done: "done",
@@ -17,7 +17,7 @@ var StatusName = map[status]string{
type Task struct { type Task struct {
Id uint Id uint
Description string Description string
Status status Status Status
Created int64 Created int64
Updated int64 Updated int64
} }