Skip to content

Commit

Permalink
feat: Command to list tags of a single file (#5)
Browse files Browse the repository at this point in the history
Added the sub command `inspect` which prints out the tags of a single file.
  • Loading branch information
Christian Häusler authored Mar 17, 2019
1 parent 5269c13 commit f2488dc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
32 changes: 32 additions & 0 deletions cmd/inspect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cmd

import (
"strings"

"github.com/corvus-ch/bilocation/tag"
"gopkg.in/alecthomas/kingpin.v2"
)

// Inspect registers the inspect sub command to the application.
func Inspect(app *kingpin.Application, cfg *config) {
c := app.Command("inspect", "show the tags of a file")
c.Action(func(_ *kingpin.ParseContext) error {
set, err := tag.Read(cfg.Path())
if err != nil {
return err
}

for name := range set {
c := set.Get(name)
if len(c) > 0 {
cfg.Log().Infof("%s (%s)", name, strings.Join(c, ", "))
} else {
cfg.Log().Info(name)
}
}
return nil
})
c.Arg("file", "path to the file").
Required().
ExistingFileVar(&cfg.path)
}
3 changes: 3 additions & 0 deletions fixtures/help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ ERROR
ERROR untag <file> <tag>...
ERROR removes a tag from a file
ERROR
ERROR inspect <file>
ERROR show the tags of a file
ERROR
ERROR search [<flags>] <query>
ERROR search for files wit a given tag
ERROR
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func App(log logr.Logger) *kingpin.Application {
cfg := cmd.NewConfig(log)
cmd.Tag(app, cfg)
cmd.Untag(app, cfg)
cmd.Inspect(app, cfg)
cmd.Search(app, cfg)
cmd.Summary(app, cfg)

Expand Down

0 comments on commit f2488dc

Please sign in to comment.