diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bfc67eadadf..d5d5651ff10 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -127,9 +127,6 @@ jobs: uses: actions/setup-go@v4 with: go-version: 1.20.x - - name: Check Cheatsheet - run: | - go run scripts/cheatsheet/main.go check - name: Check Vendor Directory # ensure our vendor directory matches up with our go modules run: | diff --git a/Makefile b/Makefile index a220b68b3bf..33e5060591a 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,7 @@ unit-test: .PHONY: test test: unit-test integration-test-all +# Generate all our auto-generated files (test list, cheatsheets, maybe other things in the future) .PHONY: generate generate: go generate ./... @@ -37,10 +38,6 @@ generate: format: gofumpt -l -w . -.PHONY: update-cheatsheet -update-cheatsheet: - go run scripts/cheatsheet/main.go generate - # For more details about integration test, see https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md. .PHONY: integration-test-tui integration-test-tui: diff --git a/docs/keybindings/Keybindings_en.md b/docs/keybindings/Keybindings_en.md index 976ea81936c..3c57562f23f 100644 --- a/docs/keybindings/Keybindings_en.md +++ b/docs/keybindings/Keybindings_en.md @@ -1,4 +1,4 @@ -_This file is auto-generated. To update, make the changes in the pkg/i18n directory and then run `go run scripts/cheatsheet/main.go generate` from the project root._ +_This file is auto-generated. To update, make the changes in the pkg/i18n directory and then run `go generate ./...` from the project root._ # Lazygit Keybindings diff --git a/docs/keybindings/Keybindings_ja.md b/docs/keybindings/Keybindings_ja.md index 419beb5dd17..42a849fe92a 100644 --- a/docs/keybindings/Keybindings_ja.md +++ b/docs/keybindings/Keybindings_ja.md @@ -1,4 +1,4 @@ -_This file is auto-generated. To update, make the changes in the pkg/i18n directory and then run `go run scripts/cheatsheet/main.go generate` from the project root._ +_This file is auto-generated. To update, make the changes in the pkg/i18n directory and then run `go generate ./...` from the project root._ # Lazygit キーバインド diff --git a/docs/keybindings/Keybindings_ko.md b/docs/keybindings/Keybindings_ko.md index 71c57714e81..025bb955938 100644 --- a/docs/keybindings/Keybindings_ko.md +++ b/docs/keybindings/Keybindings_ko.md @@ -1,4 +1,4 @@ -_This file is auto-generated. To update, make the changes in the pkg/i18n directory and then run `go run scripts/cheatsheet/main.go generate` from the project root._ +_This file is auto-generated. To update, make the changes in the pkg/i18n directory and then run `go generate ./...` from the project root._ # Lazygit 키 바인딩 diff --git a/docs/keybindings/Keybindings_nl.md b/docs/keybindings/Keybindings_nl.md index 13a868817ea..23d42e47726 100644 --- a/docs/keybindings/Keybindings_nl.md +++ b/docs/keybindings/Keybindings_nl.md @@ -1,4 +1,4 @@ -_This file is auto-generated. To update, make the changes in the pkg/i18n directory and then run `go run scripts/cheatsheet/main.go generate` from the project root._ +_This file is auto-generated. To update, make the changes in the pkg/i18n directory and then run `go generate ./...` from the project root._ # Lazygit Sneltoetsen diff --git a/docs/keybindings/Keybindings_pl.md b/docs/keybindings/Keybindings_pl.md index eae0951158f..1c1ce73aed2 100644 --- a/docs/keybindings/Keybindings_pl.md +++ b/docs/keybindings/Keybindings_pl.md @@ -1,4 +1,4 @@ -_This file is auto-generated. To update, make the changes in the pkg/i18n directory and then run `go run scripts/cheatsheet/main.go generate` from the project root._ +_This file is auto-generated. To update, make the changes in the pkg/i18n directory and then run `go generate ./...` from the project root._ # Lazygit Keybindings diff --git a/docs/keybindings/Keybindings_ru.md b/docs/keybindings/Keybindings_ru.md index ff533b60545..6e397d0a257 100644 --- a/docs/keybindings/Keybindings_ru.md +++ b/docs/keybindings/Keybindings_ru.md @@ -1,4 +1,4 @@ -_This file is auto-generated. To update, make the changes in the pkg/i18n directory and then run `go run scripts/cheatsheet/main.go generate` from the project root._ +_This file is auto-generated. To update, make the changes in the pkg/i18n directory and then run `go generate ./...` from the project root._ # Lazygit Связки клавиш diff --git a/docs/keybindings/Keybindings_zh-CN.md b/docs/keybindings/Keybindings_zh-CN.md index 620c77495b2..ed232d70b65 100644 --- a/docs/keybindings/Keybindings_zh-CN.md +++ b/docs/keybindings/Keybindings_zh-CN.md @@ -1,4 +1,4 @@ -_This file is auto-generated. To update, make the changes in the pkg/i18n directory and then run `go run scripts/cheatsheet/main.go generate` from the project root._ +_This file is auto-generated. To update, make the changes in the pkg/i18n directory and then run `go generate ./...` from the project root._ # Lazygit 按键绑定 diff --git a/docs/keybindings/Keybindings_zh-TW.md b/docs/keybindings/Keybindings_zh-TW.md index 186d02864ce..eff90a5c000 100644 --- a/docs/keybindings/Keybindings_zh-TW.md +++ b/docs/keybindings/Keybindings_zh-TW.md @@ -1,4 +1,4 @@ -_This file is auto-generated. To update, make the changes in the pkg/i18n directory and then run `go run scripts/cheatsheet/main.go generate` from the project root._ +_This file is auto-generated. To update, make the changes in the pkg/i18n directory and then run `go generate ./...` from the project root._ # Lazygit 鍵盤快捷鍵 diff --git a/pkg/cheatsheet/check.go b/pkg/cheatsheet/check.go deleted file mode 100644 index 5c4df97efc8..00000000000 --- a/pkg/cheatsheet/check.go +++ /dev/null @@ -1,77 +0,0 @@ -package cheatsheet - -import ( - "fmt" - "io/fs" - "log" - "os" - "path/filepath" - "regexp" - - "github.com/pmezard/go-difflib/difflib" -) - -func Check() { - dir := GetKeybindingsDir() - tmpDir := filepath.Join(os.TempDir(), "lazygit_cheatsheet") - err := os.RemoveAll(tmpDir) - if err != nil { - log.Fatalf("Error occurred while checking if cheatsheets are up to date: %v", err) - } - err = os.Mkdir(tmpDir, 0o700) - if err != nil { - log.Fatalf("Error occurred 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 occurred 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. If you run the script and no keybindings files are updated as a result, try rebasing onto master and trying again.\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 := os.ReadFile(path) - if err != nil { - log.Fatalf("Error occurred 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 occurred while checking if cheatsheets are up to date: %v", err) - } - - return content -} diff --git a/pkg/cheatsheet/generate.go b/pkg/cheatsheet/generate.go index 184e84a0463..392e9d64d4b 100644 --- a/pkg/cheatsheet/generate.go +++ b/pkg/cheatsheet/generate.go @@ -1,10 +1,12 @@ -// This "script" generates a file called Keybindings_{{.LANG}}.md -// in current working directory. +//go:generate go run generator.go + +// This "script" generates files called Keybindings_{{.LANG}}.md +// in the docs/keybindings directory. // -// The content of this generated file is a keybindings cheatsheet. +// The content of these generated files is a keybindings cheatsheet. // -// To generate cheatsheet in english run: -// go run scripts/generate_cheatsheet.go +// To generate the cheatsheets, run: +// go generate pkg/cheatsheet/generate.go package cheatsheet @@ -42,7 +44,7 @@ type headerWithBindings struct { } func CommandToRun() string { - return "go run scripts/cheatsheet/main.go generate" + return "go generate ./..." } func GetKeybindingsDir() string { diff --git a/pkg/cheatsheet/generator.go b/pkg/cheatsheet/generator.go new file mode 100644 index 00000000000..1708a28e8b0 --- /dev/null +++ b/pkg/cheatsheet/generator.go @@ -0,0 +1,14 @@ +//go:build ignore + +package main + +import ( + "fmt" + + "github.com/jesseduffield/lazygit/pkg/cheatsheet" +) + +func main() { + fmt.Printf("Generating cheatsheets in %s...\n", cheatsheet.GetKeybindingsDir()) + cheatsheet.Generate() +} diff --git a/scripts/cheatsheet/main.go b/scripts/cheatsheet/main.go deleted file mode 100644 index 742bdc7d73b..00000000000 --- a/scripts/cheatsheet/main.go +++ /dev/null @@ -1,27 +0,0 @@ -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.GetKeybindingsDir()) - case "check": - cheatsheet.Check() - default: - log.Fatal("\nUnknown command. Expected one of 'generate', 'check'") - } -}