cheat allows many cheapaths, and the order in the config file is significant: the last cheatpaths take precedence over the earlier ones, so when there are many matching cheat files, the one that is displayed is the one in the latter cheatpath. This makes it possible to config a public and a private cheatpath, and list the private one at the end, thus a private cheats will always override the public one when a match is found in both of them.
chat also added an option to display all matching cheat files, via --all CLI parameter. However, the cheats are displayed in the cheatpaths listed order, which means the less important cheatfile will be displayed first rather than last. To use the example above, the private match will be displayed last (after the less important public one) rather than first (before the public one).
This means cheat foo displays the private foo cheat, and cheat -a foo displays the public one followed by the private one, rather than the private one first.
The fix is very localized and trivial: when using --alll, reverse the list so that any subsequent processing is done in priority order.
// if --all was passed, display cheatsheets from all cheatpaths
allFlag, _ := cmd.Flags().GetBool("all")
if allFlag {
+ for i, j := 0, len(cheatsheets)-1; i < j; i, j = i+1, j-1 {
+ cheatsheets[i], cheatsheets[j] = cheatsheets[j], cheatsheets[i]
+ }
+
// iterate over the cheatpaths
out := ""
for _, cheatpath := range cheatsheets {
Would it be possible to make the above change in the mainline code base?
This makes it more consistent with the current spirit (latter cheatpaths override sooner ones, hence they are more important).
Furthermore, I think other people would expect this too: see the last comment that lead to implementation of --all in issue #548.
(happy to do a PR if you would prefer that, I put the code inline since is trivial and PRs are currently not accepted)
cheatallows many cheapaths, and the order in the config file is significant: the last cheatpaths take precedence over the earlier ones, so when there are many matching cheat files, the one that is displayed is the one in the latter cheatpath. This makes it possible to config a public and a private cheatpath, and list the private one at the end, thus a private cheats will always override the public one when a match is found in both of them.chatalso added an option to display all matching cheat files, via--allCLI parameter. However, the cheats are displayed in the cheatpaths listed order, which means the less important cheatfile will be displayed first rather than last. To use the example above, the private match will be displayed last (after the less important public one) rather than first (before the public one).This means
cheat foodisplays the private foo cheat, andcheat -a foodisplays the public one followed by the private one, rather than the private one first.The fix is very localized and trivial: when using
--alll, reverse the list so that any subsequent processing is done in priority order.Would it be possible to make the above change in the mainline code base?
This makes it more consistent with the current spirit (latter cheatpaths override sooner ones, hence they are more important).
Furthermore, I think other people would expect this too: see the last comment that lead to implementation of
--allin issue #548.(happy to do a PR if you would prefer that, I put the code inline since is trivial and PRs are currently not accepted)