Skip to content

Commit

Permalink
Implement cat command
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielseibel1 committed Jun 2, 2024
1 parent 726f9f0 commit 0b86242
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
11 changes: 8 additions & 3 deletions .godo/godo.json
Original file line number Diff line number Diff line change
@@ -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":{}}}
41 changes: 41 additions & 0 deletions commands/cat.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 2 additions & 0 deletions commands/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 0b86242

Please sign in to comment.