forked from jesseduffield/lazygit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e66d27
commit e8a1a4f
Showing
11 changed files
with
155 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package cheatsheet | ||
|
||
import ( | ||
"fmt" | ||
"io/fs" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
|
||
"github.com/pmezard/go-difflib/difflib" | ||
) | ||
|
||
func Check() { | ||
dir := GetDir() | ||
tmpDir := filepath.Join(os.TempDir(), "lazygit_cheatsheet") | ||
err := os.RemoveAll(tmpDir) | ||
if err != nil { | ||
log.Fatalf("Error occured while checking if cheatsheets are up to date: %v", err) | ||
} | ||
err = os.Mkdir(tmpDir, 0700) | ||
if err != nil { | ||
log.Fatalf("Error occured while checking if cheatsheets are up to date: %v", err) | ||
} | ||
|
||
generateAtDir(tmpDir) | ||
defer os.RemoveAll(tmpDir) | ||
|
||
actualContent := obtainContent(dir) | ||
expectedContent := obtainContent(tmpDir) | ||
|
||
if expectedContent == "" { | ||
log.Fatal("empty expected content") | ||
} | ||
|
||
if actualContent != expectedContent { | ||
err := difflib.WriteUnifiedDiff(os.Stdout, difflib.UnifiedDiff{ | ||
A: difflib.SplitLines(expectedContent), | ||
B: difflib.SplitLines(actualContent), | ||
FromFile: "Expected", | ||
FromDate: "", | ||
ToFile: "Actual", | ||
ToDate: "", | ||
Context: 1, | ||
}) | ||
if err != nil { | ||
log.Fatalf("Error occured while checking if cheatsheets are up to date: %v", err) | ||
} | ||
fmt.Printf("\nCheatsheets are out of date. Please run `%s` at the project root and commit the changes\n", CommandToRun()) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Println("\nCheatsheets are up to date") | ||
} | ||
|
||
func obtainContent(dir string) string { | ||
re := regexp.MustCompile(`Keybindings_\w+\.md$`) | ||
|
||
content := "" | ||
err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error { | ||
if re.MatchString(path) { | ||
bytes, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
log.Fatalf("Error occured while checking if cheatsheets are up to date: %v", err) | ||
} | ||
content += fmt.Sprintf("\n%s\n\n", filepath.Base(path)) | ||
content += string(bytes) | ||
} | ||
|
||
return nil | ||
}) | ||
|
||
if err != nil { | ||
log.Fatalf("Error occured while checking if cheatsheets are up to date: %v", err) | ||
} | ||
|
||
return content | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/jesseduffield/lazygit/pkg/cheatsheet" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 2 { | ||
log.Fatal("Please provide a command: one of 'generate', 'check'") | ||
} | ||
|
||
command := os.Args[1] | ||
|
||
switch command { | ||
case "generate": | ||
cheatsheet.Generate() | ||
fmt.Printf("\nGenerated cheatsheets in %s\n", cheatsheet.GetDir()) | ||
case "check": | ||
cheatsheet.Check() | ||
default: | ||
log.Fatal("\nUnknown command. Expected one of 'generate', 'check'") | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters