mirror of
https://github.com/cheat/cheat.git
synced 2026-03-07 19:23:34 +01:00
feat: implement --all flag
Implement an `--all` flag that can be used to view cheatsheets on all chaetpaths. (Resolves #548)
This commit is contained in:
@@ -30,9 +30,37 @@ func cmdView(opts map[string]interface{}, conf config.Config) {
|
||||
)
|
||||
}
|
||||
|
||||
// consolidate the cheatsheets found on all paths into a single map of
|
||||
// `title` => `sheet` (ie, allow more local cheatsheets to override less
|
||||
// local cheatsheets)
|
||||
// if --all was passed, display cheatsheets from all cheatpaths
|
||||
if opts["--all"].(bool) {
|
||||
// iterate over the cheatpaths
|
||||
for _, cheatpath := range cheatsheets {
|
||||
|
||||
// if the cheatpath contains the specified cheatsheet, display it
|
||||
if sheet, ok := cheatpath[cheatsheet]; ok {
|
||||
|
||||
// identify the matching cheatsheet
|
||||
fmt.Println(fmt.Sprintf("%s %s",
|
||||
display.Underline(sheet.Title),
|
||||
display.Faint(fmt.Sprintf("(%s)", sheet.CheatPath)),
|
||||
))
|
||||
|
||||
// apply colorization if requested
|
||||
if conf.Color(opts) {
|
||||
sheet.Colorize(conf)
|
||||
}
|
||||
|
||||
// display the cheatsheet
|
||||
display.Display(display.Indent(sheet.Text), conf)
|
||||
}
|
||||
}
|
||||
|
||||
// exit early
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// otherwise, consolidate the cheatsheets found on all paths into a single
|
||||
// map of `title` => `sheet` (ie, allow more local cheatsheets to override
|
||||
// less local cheatsheets)
|
||||
consolidated := sheets.Consolidate(cheatsheets)
|
||||
|
||||
// fail early if the requested cheatsheet does not exist
|
||||
|
||||
Reference in New Issue
Block a user