2021-08-20 08:18:26 +02:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2022-06-05 15:00:28 +02:00
|
|
|
"sort"
|
2021-08-20 08:18:26 +02:00
|
|
|
"strings"
|
|
|
|
|
2021-09-19 11:59:26 +02:00
|
|
|
"ewintr.nl/gte/cmd/cli/format"
|
|
|
|
"ewintr.nl/gte/internal/configuration"
|
|
|
|
"ewintr.nl/gte/internal/process"
|
|
|
|
"ewintr.nl/gte/internal/storage"
|
2022-06-05 15:00:28 +02:00
|
|
|
"ewintr.nl/gte/internal/task"
|
2021-08-20 08:18:26 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Project struct {
|
|
|
|
lister *process.List
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewProject(conf *configuration.Configuration, cmdArgs []string) (*Project, error) {
|
|
|
|
local, err := storage.NewSqlite(conf.Sqlite())
|
|
|
|
if err != nil {
|
|
|
|
return &Project{}, err
|
|
|
|
}
|
|
|
|
if len(cmdArgs) < 1 {
|
|
|
|
return &Project{}, ErrInvalidAmountOfArgs
|
|
|
|
}
|
|
|
|
reqs := process.ListReqs{
|
2021-09-07 06:50:30 +02:00
|
|
|
Project: strings.ToLower(cmdArgs[0]),
|
|
|
|
ApplyUpdates: true,
|
2021-08-20 08:18:26 +02:00
|
|
|
}
|
|
|
|
lister := process.NewList(local, reqs)
|
|
|
|
|
|
|
|
return &Project{
|
|
|
|
lister: lister,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Project) Do() string {
|
|
|
|
res, err := p.lister.Process()
|
|
|
|
if err != nil {
|
|
|
|
return format.FormatError(err)
|
|
|
|
}
|
|
|
|
|
2022-06-05 15:00:28 +02:00
|
|
|
sort.Sort(task.ByDefault(res.Tasks))
|
|
|
|
cols := []format.Column{format.COL_ID, format.COL_STATUS, format.COL_DUE, format.COL_ACTION}
|
|
|
|
|
|
|
|
return format.FormatTaskTable(res.Tasks, cols)
|
2021-08-20 08:18:26 +02:00
|
|
|
}
|