list folder and project command
This commit is contained in:
parent
fbc2a3d400
commit
8cc7e888ed
|
@ -23,7 +23,6 @@ func Parse(args []string, conf *configuration.Configuration) (Command, error) {
|
|||
if len(args) == 0 {
|
||||
return NewEmpty()
|
||||
}
|
||||
|
||||
cmd, cmdArgs := args[0], args[1:]
|
||||
|
||||
id, err := strconv.Atoi(cmd)
|
||||
|
@ -38,6 +37,8 @@ func Parse(args []string, conf *configuration.Configuration) (Command, error) {
|
|||
return NewToday(conf)
|
||||
case "tomorrow":
|
||||
return NewTomorrow(conf)
|
||||
case "list":
|
||||
return NewList(conf, cmdArgs)
|
||||
case "add":
|
||||
return NewAdd(conf, cmdArgs)
|
||||
default:
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.ewintr.nl/gte/cmd/cli/format"
|
||||
"git.ewintr.nl/gte/internal/configuration"
|
||||
"git.ewintr.nl/gte/internal/process"
|
||||
"git.ewintr.nl/gte/internal/storage"
|
||||
"git.ewintr.nl/gte/internal/task"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrUnknownFolder = errors.New("unknown folder")
|
||||
)
|
||||
|
||||
// List lists all the tasks in a project or a folder
|
||||
type List struct {
|
||||
local storage.LocalRepository
|
||||
lister *process.List
|
||||
}
|
||||
|
||||
func (l *List) Cmd() string { return "list" }
|
||||
|
||||
func NewList(conf *configuration.Configuration, cmdArgs []string) (*List, error) {
|
||||
local, err := storage.NewSqlite(conf.Sqlite())
|
||||
if err != nil {
|
||||
return &List{}, err
|
||||
}
|
||||
fmt.Printf("args: %+v\n", cmdArgs)
|
||||
if len(cmdArgs) < 2 {
|
||||
return &List{}, ErrInvalidAmountOfArgs
|
||||
}
|
||||
|
||||
reqs, err := parseReqs(cmdArgs[0], cmdArgs[1])
|
||||
if err != nil {
|
||||
return &List{}, err
|
||||
}
|
||||
lister := process.NewList(local, reqs)
|
||||
|
||||
return &List{
|
||||
local: local,
|
||||
lister: lister,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (l *List) Do() string {
|
||||
res, err := l.lister.Process()
|
||||
if err != nil {
|
||||
return format.FormatError(err)
|
||||
}
|
||||
|
||||
if len(res.Tasks) == 0 {
|
||||
return "no tasks there\n"
|
||||
}
|
||||
|
||||
return format.FormatTaskTable(l.local, res.Tasks)
|
||||
}
|
||||
|
||||
func parseReqs(kind, item string) (process.ListReqs, error) {
|
||||
item = strings.ToLower(item)
|
||||
switch kind {
|
||||
case "folder":
|
||||
for _, folder := range task.KnownFolders {
|
||||
if item == strings.ToLower(folder) {
|
||||
return process.ListReqs{
|
||||
Folder: folder,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
return process.ListReqs{}, ErrUnknownFolder
|
||||
case "project":
|
||||
return process.ListReqs{
|
||||
Project: item,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return process.ListReqs{}, process.ErrInvalidReqs
|
||||
}
|
|
@ -30,10 +30,11 @@ func FormatTaskTable(local storage.LocalRepository, tasks []*task.Task) string {
|
|||
}
|
||||
|
||||
func FormatTask(id int, t *task.Task) string {
|
||||
output := fmt.Sprintf(`action: %s
|
||||
output := fmt.Sprintf(`folder: %s
|
||||
action: %s
|
||||
project: %s
|
||||
due: %s
|
||||
`, t.Action, t.Project, t.Due.String())
|
||||
`, t.Folder, t.Action, t.Project, t.Due.String())
|
||||
if t.IsRecurrer() {
|
||||
output += fmt.Sprintf("recur:%s", t.Recur.String())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue