From f2488dc37b71be01e11f07ac66de21cbb3889537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20H=C3=A4usler?= Date: Sun, 17 Mar 2019 09:08:33 +0100 Subject: [PATCH] feat: Command to list tags of a single file (#5) Added the sub command `inspect` which prints out the tags of a single file. --- cmd/inspect.go | 32 ++++++++++++++++++++++++++++++++ fixtures/help.golden | 3 +++ main.go | 1 + 3 files changed, 36 insertions(+) create mode 100644 cmd/inspect.go diff --git a/cmd/inspect.go b/cmd/inspect.go new file mode 100644 index 0000000..4fc8e6f --- /dev/null +++ b/cmd/inspect.go @@ -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) +} diff --git a/fixtures/help.golden b/fixtures/help.golden index 5c9237d..7c3c426 100644 --- a/fixtures/help.golden +++ b/fixtures/help.golden @@ -16,6 +16,9 @@ ERROR ERROR untag ... ERROR removes a tag from a file ERROR +ERROR inspect +ERROR show the tags of a file +ERROR ERROR search [] ERROR search for files wit a given tag ERROR diff --git a/main.go b/main.go index 8fa3aa9..70d6c51 100644 --- a/main.go +++ b/main.go @@ -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)