Skip to content

Commit

Permalink
Merge pull request #688 from chrisallenlane/4.2.7
Browse files Browse the repository at this point in the history
4.2.7
  • Loading branch information
chrisallenlane committed Aug 5, 2022
2 parents cfd1702 + 8130b2f commit 73f80bd
Show file tree
Hide file tree
Showing 23 changed files with 55 additions and 90 deletions.
4 changes: 2 additions & 2 deletions INSTALLING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ On Unix-like systems, you may simply paste the following snippet into your termi

```sh
cd /tmp \
&& wget https://github.com/cheat/cheat/releases/download/4.2.5/cheat-linux-amd64.gz \
&& wget https://github.com/cheat/cheat/releases/download/4.2.7/cheat-linux-amd64.gz \
&& gunzip cheat-linux-amd64.gz \
&& chmod +x cheat-linux-amd64 \
&& sudo mv cheat-linux-amd64 /usr/local/bin/cheat
```

You may need to need to change the version number (`4.2.5`) and the archive
You may need to need to change the version number (`4.2.7`) and the archive
(`cheat-linux-amd64.gz`) depending on your platform.

See the [releases page][releases] for a list of supported platforms.
Expand Down
6 changes: 1 addition & 5 deletions cmd/cheat/cmd_directories.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ func cmdDirectories(opts map[string]interface{}, conf config.Config) {

// generate sorted, columnized output
for _, path := range conf.Cheatpaths {
fmt.Fprintln(w, fmt.Sprintf(
"%s:\t%s",
path.Name,
path.Path,
))
fmt.Fprintf(w, "%s:\t%s\n", path.Name, path.Path)
}

// write columnized output to stdout
Expand Down
2 changes: 1 addition & 1 deletion cmd/cheat/cmd_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func cmdEdit(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))
fmt.Fprintf(os.Stderr, "failed to list cheatsheets: %v\n", err)
os.Exit(1)
}

Expand Down
14 changes: 3 additions & 11 deletions cmd/cheat/cmd_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func cmdList(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))
fmt.Fprintf(os.Stderr, "failed to list cheatsheets: %v\n", err)
os.Exit(1)
}

Expand Down Expand Up @@ -63,10 +63,7 @@ func cmdList(opts map[string]interface{}, conf config.Config) {
// compile the regex
reg, err := regexp.Compile(pattern)
if err != nil {
fmt.Fprintln(
os.Stderr,
fmt.Sprintf("failed to compile regexp: %s, %v", pattern, err),
)
fmt.Fprintf(os.Stderr, "failed to compile regexp: %s, %v\n", pattern, err)
os.Exit(1)
}

Expand Down Expand Up @@ -95,12 +92,7 @@ func cmdList(opts map[string]interface{}, conf config.Config) {

// generate sorted, columnized output
for _, sheet := range flattened {
fmt.Fprintln(w, fmt.Sprintf(
"%s\t%s\t%s",
sheet.Title,
sheet.Path,
strings.Join(sheet.Tags, ","),
))
fmt.Fprintf(w, "%s\t%s\t%s\n", sheet.Title, sheet.Path, strings.Join(sheet.Tags, ","))
}

// write columnized output to stdout
Expand Down
8 changes: 4 additions & 4 deletions cmd/cheat/cmd_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func cmdRemove(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))
fmt.Fprintf(os.Stderr, "failed to list cheatsheets: %v\n", err)
os.Exit(1)
}

Expand All @@ -37,19 +37,19 @@ func cmdRemove(opts map[string]interface{}, conf config.Config) {
// fail early if the requested cheatsheet does not exist
sheet, ok := consolidated[cheatsheet]
if !ok {
fmt.Fprintln(os.Stderr, fmt.Sprintf("No cheatsheet found for '%s'.\n", cheatsheet))
fmt.Fprintf(os.Stderr, "No cheatsheet found for '%s'.\n", cheatsheet)
os.Exit(2)
}

// fail early if the sheet is read-only
if sheet.ReadOnly {
fmt.Fprintln(os.Stderr, fmt.Sprintf("cheatsheet '%s' is read-only.", cheatsheet))
fmt.Fprintf(os.Stderr, "cheatsheet '%s' is read-only.\n", cheatsheet)
os.Exit(1)
}

// otherwise, attempt to delete the sheet
if err := os.Remove(sheet.Path); err != nil {
fmt.Fprintln(os.Stderr, fmt.Sprintf("failed to delete sheet: %s, %v", sheet.Title, err))
fmt.Fprintf(os.Stderr, "failed to delete sheet: %s, %v\n", sheet.Title, err)
os.Exit(1)
}
}
28 changes: 15 additions & 13 deletions cmd/cheat/cmd_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func cmdSearch(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))
fmt.Fprintf(os.Stderr, "failed to list cheatsheets: %v\n", err)
os.Exit(1)
}

Expand Down Expand Up @@ -55,13 +55,13 @@ func cmdSearch(opts map[string]interface{}, conf config.Config) {
// compile the regex
reg, err := regexp.Compile(pattern)
if err != nil {
fmt.Fprintln(os.Stderr, fmt.Sprintf("failed to compile regexp: %s, %v", pattern, err))
fmt.Fprintf(os.Stderr, "failed to compile regexp: %s, %v\n", pattern, err)
os.Exit(1)
}

// `Search` will return text entries that match the search terms. We're
// using it here to overwrite the prior cheatsheet Text, filtering it to
// only what is relevant
// `Search` will return text entries that match the search terms.
// We're using it here to overwrite the prior cheatsheet Text,
// filtering it to only what is relevant.
sheet.Text = sheet.Search(reg)

// if the sheet did not match the search, ignore it and move on
Expand All @@ -74,22 +74,24 @@ func cmdSearch(opts map[string]interface{}, conf config.Config) {
sheet.Colorize(conf)
}

// display the cheatsheet title and path
out += fmt.Sprintf("%s %s\n",
display.Underline(sheet.Title),
// display the cheatsheet body
out += fmt.Sprintf(
"%s %s\n%s\n",
// append the cheatsheet title
sheet.Title,
// append the cheatsheet path
display.Faint(fmt.Sprintf("(%s)", sheet.CheatPath), conf),
// indent each line of content
display.Indent(sheet.Text),
)

// indent each line of content
out += display.Indent(sheet.Text) + "\n"
}
}

// trim superfluous newlines
out = strings.TrimSpace(out)

// display the output
// NB: resist the temptation to call `display.Display` multiple times in
// the loop above. That will not play nicely with the paginator.
// NB: resist the temptation to call `display.Write` multiple times in the
// loop above. That will not play nicely with the paginator.
display.Write(out, conf)
}
2 changes: 1 addition & 1 deletion cmd/cheat/cmd_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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))
fmt.Fprintf(os.Stderr, "failed to list cheatsheets: %v\n", err)
os.Exit(1)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/cheat/cmd_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func cmdView(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))
fmt.Fprintf(os.Stderr, "failed to list cheatsheets: %v\n", err)
os.Exit(1)
}

Expand All @@ -41,7 +41,7 @@ func cmdView(opts map[string]interface{}, conf config.Config) {

// identify the matching cheatsheet
out += fmt.Sprintf("%s %s\n",
display.Underline(sheet.Title),
sheet.Title,
display.Faint(fmt.Sprintf("(%s)", sheet.CheatPath), conf),
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/cheat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/cheat/cheat/internal/installer"
)

const version = "4.2.6"
const version = "4.2.7"

func main() {

Expand Down
2 changes: 1 addition & 1 deletion internal/cheatpath/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestFilterFailure(t *testing.T) {
}

// filter the paths
paths, err := Filter(paths, "qux")
_, err := Filter(paths, "qux")
if err == nil {
t.Errorf("failed to return an error on non-existent cheatpath")
}
Expand Down
4 changes: 1 addition & 3 deletions internal/cheatpath/writeable.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ func Writeable(cheatpaths []Cheatpath) (Cheatpath, error) {
// NB: we're going backwards because we assume that the most "local"
// cheatpath will be specified last in the configs
for i := len(cheatpaths) - 1; i >= 0; i-- {

// if the cheatpath is not read-only, it is writeable, and thus returned
if cheatpaths[i].ReadOnly == false {
if !cheatpaths[i].ReadOnly {
return cheatpaths[i], nil
}

}

// otherwise, return an error
Expand Down
3 changes: 1 addition & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand All @@ -29,7 +28,7 @@ type Config struct {
func New(opts map[string]interface{}, confPath string, resolve bool) (Config, error) {

// read the config file
buf, err := ioutil.ReadFile(confPath)
buf, err := os.ReadFile(confPath)
if err != nil {
return Config{}, fmt.Errorf("could not read config file: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
)
Expand All @@ -16,7 +15,7 @@ func Init(confpath string, configs string) error {
}

// write the config file
if err := ioutil.WriteFile(confpath, []byte(configs), 0644); err != nil {
if err := os.WriteFile(confpath, []byte(configs), 0644); err != nil {
return fmt.Errorf("failed to create file: %v", err)
}

Expand Down
5 changes: 2 additions & 3 deletions internal/config/init_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"io/ioutil"
"os"
"testing"
)
Expand All @@ -10,7 +9,7 @@ import (
func TestInit(t *testing.T) {

// initialize a temporary config file
confFile, err := ioutil.TempFile("", "cheat-test")
confFile, err := os.CreateTemp("", "cheat-test")
if err != nil {
t.Errorf("failed to create temp file: %v", err)
}
Expand All @@ -25,7 +24,7 @@ func TestInit(t *testing.T) {
}

// read back the config file contents
bytes, err := ioutil.ReadFile(confFile.Name())
bytes, err := os.ReadFile(confFile.Name())
if err != nil {
t.Errorf("failed to read config file: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/config/path_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"io/ioutil"
"os"
"testing"
)
Expand All @@ -24,7 +23,7 @@ func TestPathConfigNotExists(t *testing.T) {
func TestPathConfigExists(t *testing.T) {

// initialize a temporary config file
confFile, err := ioutil.TempFile("", "cheat-test")
confFile, err := os.CreateTemp("", "cheat-test")
if err != nil {
t.Errorf("failed to create temp file: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/display/faint.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func Faint(str string, conf config.Config) string {
// make `str` faint only if colorization has been requested
if conf.Colorize {
return fmt.Sprintf(fmt.Sprintf("\033[2m%s\033[0m", str))
return fmt.Sprintf("\033[2m%s\033[0m", str)
}

// otherwise, return the string unmodified
Expand Down
8 changes: 0 additions & 8 deletions internal/display/underline.go

This file was deleted.

14 changes: 0 additions & 14 deletions internal/display/underline_test.go

This file was deleted.

9 changes: 4 additions & 5 deletions internal/display/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ func Write(out string, conf config.Config) {
pager := parts[0]
args := parts[1:]

// run the pager
// configure the pager
cmd := exec.Command(pager, args...)
cmd.Stdin = strings.NewReader(out)
cmd.Stdout = os.Stdout

// handle errors
err := cmd.Run()
if err != nil {
fmt.Fprintln(os.Stderr, fmt.Sprintf("failed to write to pager: %v", err))
// run the pager and handle errors
if err := cmd.Run(); err != nil {
fmt.Fprintf(os.Stderr, "failed to write to pager: %v\n", err)
os.Exit(1)
}
}
2 changes: 1 addition & 1 deletion internal/installer/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func Prompt(prompt string, def bool) (bool, error) {
reader := bufio.NewReader(os.Stdin)

// display the prompt
fmt.Print(fmt.Sprintf("%s: ", prompt))
fmt.Printf("%s: ", prompt)

// read the answer
ans, err := reader.ReadString('\n')
Expand Down
Loading

0 comments on commit 73f80bd

Please sign in to comment.