mirror of
https://github.com/cheat/cheat.git
synced 2024-11-22 05:51:35 +01:00
feat: single-sheet searching
`--search` will now honor the `<cheatsheet>` argument, making it possible to constrain a search to a single cheatsheet.
This commit is contained in:
parent
7b4a268ebd
commit
3e4c1818a9
@ -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 <cheatsheet> was provided, search that single sheet only
|
||||
if opts["<cheatsheet>"] != nil {
|
||||
|
||||
cheatsheet := opts["<cheatsheet>"].(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) {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user