From 0b862429268c68265cf5c92fd647880f8654cbc4 Mon Sep 17 00:00:00 2001 From: gabrielseibel1 Date: Sun, 2 Jun 2024 17:55:45 -0300 Subject: [PATCH] Implement cat command --- .godo/godo.json | 11 ++++++++--- commands/cat.go | 41 +++++++++++++++++++++++++++++++++++++++++ commands/parser.go | 2 ++ 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 commands/cat.go diff --git a/.godo/godo.json b/.godo/godo.json index d7800c3..3f8bb63 100644 --- a/.godo/godo.json +++ b/.godo/godo.json @@ -1,3 +1,8 @@ -{"UI tags":{"id":"UI tags","description":"filter the items by tags in the UI, listing the tags for selection","duration":0,"done":false,"tags":{}},"list tags":{"id":"list tags","description":"command like 'godo list tag1 tag2 tag3' that lists items in tags","duration":1800000000000,"done":true,"tags":{}},"ordering":{"id":"ordering","description":"sort by custom order","duration":0,"done":false,"tags":{}},"tags":{"id":"tags","description":"command like 'godo tags' that lists the existing tags","duration":0,"done":false,"tags":{}},"untag":{"id":"untag","description":"command like tag but deletes the tag from items","duration":5400000000000,"done":true,"tags":{}}} -":{}}} -ription":"command like tag but deletes the tag from items","duration":5400000000000,"done":true,"tags":{}}} +{"UI tags":{"id":"UI tags","description":"filter the items by tags in the UI, listing the tags for selection","duration":0,"done":false,"tags":{}},"list tags":{"id":"list tags","description":"command like 'godo list tag1 tag2 tag3' that lists items in tags","duration":1800000000000,"done":true,"tags":{}},"ordering":{"id":"ordering","description":"sort by custom order","duration":0,"done":false,"tags":{}},"tags":{"id":"tags","description":"command like 'godo tags' that lists the existing tags","duration":0,"done":true,"tags":{}},"untag":{"id":"untag","description":"command like tag but deletes the tag from items","duration":5400000000000,"done":true,"tags":{}}} + +K":{}}}} +K":{}}}} +RK":{}}}} +RK":{}}}} +RK":{}}}} +e tag from items","duration":5400000000000,"done":true,"tags":{}}} diff --git a/commands/cat.go b/commands/cat.go new file mode 100644 index 0000000..1d036fc --- /dev/null +++ b/commands/cat.go @@ -0,0 +1,41 @@ +package commands + +import ( + "fmt" + + "github.com/gabrielseibel1/godo/data" + "github.com/gabrielseibel1/godo/types" + "golang.org/x/exp/maps" +) + +const CatCommandName CommandName = "cat" + +type Cat struct { + repo data.Repository +} + +func (c *Cat) Parameterize(args []string) error { + if len(args) != 0 { + return errArgsCount(0, len(args)) + } + return nil +} + +func (c *Cat) Execute() error { + as, err := c.repo.List() + if err != nil { + return err + } + tags := make(map[types.ID]struct{}) + for _, a := range as { + maps.Copy(tags, a.Tags()) + } + for tag := range tags { + fmt.Println(tag) + } + return nil +} + +func (c *Cat) String() string { + return fmt.Sprintf("command %s", CatCommandName) +} diff --git a/commands/parser.go b/commands/parser.go index 67cdc05..89a8757 100644 --- a/commands/parser.go +++ b/commands/parser.go @@ -31,6 +31,8 @@ func NewParser(deps Deps) Parser { cmd = &List{repo: deps.Repo, display: deps.Displayer} case string(SublistCommandName): cmd = &Sublist{repo: deps.Repo, display: deps.Displayer} + case string(CatCommandName): + cmd = &Cat{repo: deps.Repo} case string(GetCommandName): cmd = &Get{repo: deps.Repo, display: deps.Displayer} case string(CreateCommandName):