feat: implements --tags

Implements `--tags`, which lists all tags in use.
This commit is contained in:
Chris Lane
2019-11-14 21:50:49 -05:00
parent 09c29a322f
commit aeaf01e1de
6 changed files with 120 additions and 0 deletions

25
cmd/cheat/cmd_tags.go Normal file
View File

@ -0,0 +1,25 @@
package main
import (
"fmt"
"os"
"github.com/cheat/cheat/internal/config"
"github.com/cheat/cheat/internal/sheets"
)
// cmdTags lists all tags in use.
func cmdTags(opts map[string]interface{}, conf config.Config) {
// load the cheatsheets
cheatsheets, err := sheets.Load(conf.Cheatpaths)
if err != nil {
fmt.Fprintln(os.Stderr, fmt.Sprintf("failed to list cheatsheets: %v", err))
os.Exit(1)
}
// write sheet tags to stdout
for _, tag := range sheets.Tags(cheatsheets) {
fmt.Println(tag)
}
}

View File

@ -11,6 +11,7 @@ Options:
-r --regex Treat search <phrase> as a regex
-s --search=<phrase> Search cheatsheets for <phrase>
-t --tag=<tag> Return only sheets matching <tag>
-T --tags List all tags in use
-v --version Print the version number
Examples:
@ -33,6 +34,9 @@ Examples:
To list all available cheatsheets:
cheat -l
To list all tags in use:
cheat -T
To list available cheatsheets that are tagged as "personal":
cheat -l -t personal

View File

@ -76,6 +76,9 @@ func main() {
case opts["--list"].(bool):
cmd = cmdList
case opts["--tags"].(bool):
cmd = cmdTags
case opts["--search"] != nil:
cmd = cmdSearch

View File

@ -20,6 +20,7 @@ Options:
-r --regex Treat search <phrase> as a regex
-s --search=<phrase> Search cheatsheets for <phrase>
-t --tag=<tag> Return only sheets matching <tag>
-T --tags List all tags in use
-v --version Print the version number
Examples: