-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Command to list tags of a single file (#5)
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
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters