diff --git a/cmd/cheat/cmd_search.go b/cmd/cheat/cmd_search.go index 5c64da9..124741e 100644 --- a/cmd/cheat/cmd_search.go +++ b/cmd/cheat/cmd_search.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/cheat/cheat/internal/config" + "github.com/cheat/cheat/internal/sheet" "github.com/cheat/cheat/internal/sheets" ) @@ -35,6 +36,23 @@ func cmdSearch(opts map[string]interface{}, conf config.Config) { // local cheatsheets) consolidated := sheets.Consolidate(cheatsheets) + // if was provided, search that single sheet only + if opts[""] != nil { + + cheatsheet := opts[""].(string) + + // assert that the cheatsheet exists + s, ok := consolidated[cheatsheet] + if !ok { + fmt.Printf("No cheatsheet found for '%s'.\n", cheatsheet) + os.Exit(0) + } + + consolidated = map[string]sheet.Sheet{ + cheatsheet: s, + } + } + // sort the cheatsheets alphabetically, and search for matches for _, sheet := range sheets.Sort(consolidated) {