mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-11-24 08:52:21 +02:00
add cheatsheet check script
This commit is contained in:
parent
8e66d2761e
commit
e8a1a4ffc0
22
.github/workflows/ci.yml
vendored
22
.github/workflows/ci.yml
vendored
@ -63,3 +63,25 @@ jobs:
|
|||||||
- name: Build darwin binary
|
- name: Build darwin binary
|
||||||
run: |
|
run: |
|
||||||
GOOS=darwin go build
|
GOOS=darwin go build
|
||||||
|
check-cheatsheet:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
GOFLAGS: -mod=vendor
|
||||||
|
GOARCH: amd64
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: 1.16.x
|
||||||
|
- name: Cache build
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.cache/go-build
|
||||||
|
key: ${{runner.os}}-go-${{hashFiles('**/go.sum')}}-build
|
||||||
|
restore-keys: |
|
||||||
|
${{runner.os}}-go-
|
||||||
|
- name: Check Cheatsheet
|
||||||
|
run: |
|
||||||
|
go run scripts/cheatsheet/main.go check
|
||||||
|
@ -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/generate_cheatsheet.go` from the project root.
|
# 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.
|
||||||
|
|
||||||
# Lazygit Keybindings
|
# Lazygit Keybindings
|
||||||
|
|
||||||
|
@ -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/generate_cheatsheet.go` from the project root.
|
# 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.
|
||||||
|
|
||||||
# Lazygit Sneltoetsen
|
# Lazygit Sneltoetsen
|
||||||
|
|
||||||
|
@ -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/generate_cheatsheet.go` from the project root.
|
# 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.
|
||||||
|
|
||||||
# Lazygit Keybindings
|
# Lazygit Keybindings
|
||||||
|
|
||||||
|
@ -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/generate_cheatsheet.go` from the project root.
|
# 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.
|
||||||
|
|
||||||
# Lazygit 按键绑定
|
# Lazygit 按键绑定
|
||||||
|
|
||||||
|
1
go.mod
1
go.mod
@ -33,6 +33,7 @@ require (
|
|||||||
github.com/mgutz/str v1.2.0
|
github.com/mgutz/str v1.2.0
|
||||||
github.com/onsi/ginkgo v1.10.3 // indirect
|
github.com/onsi/ginkgo v1.10.3 // indirect
|
||||||
github.com/onsi/gomega v1.7.1 // indirect
|
github.com/onsi/gomega v1.7.1 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/sahilm/fuzzy v0.1.0
|
github.com/sahilm/fuzzy v0.1.0
|
||||||
github.com/sirupsen/logrus v1.4.2
|
github.com/sirupsen/logrus v1.4.2
|
||||||
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad
|
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad
|
||||||
|
79
pkg/cheatsheet/check.go
Normal file
79
pkg/cheatsheet/check.go
Normal file
@ -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
|
||||||
|
}
|
@ -4,21 +4,21 @@
|
|||||||
// The content of this generated file is a keybindings cheatsheet.
|
// The content of this generated file is a keybindings cheatsheet.
|
||||||
//
|
//
|
||||||
// To generate cheatsheet in english run:
|
// To generate cheatsheet in english run:
|
||||||
// LANG=en go run scripts/generate_cheatsheet.go
|
// go run scripts/generate_cheatsheet.go
|
||||||
|
|
||||||
package main
|
package cheatsheet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/app"
|
"github.com/jesseduffield/lazygit/pkg/app"
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui"
|
"github.com/jesseduffield/lazygit/pkg/gui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/i18n"
|
"github.com/jesseduffield/lazygit/pkg/i18n"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/integration"
|
||||||
)
|
)
|
||||||
|
|
||||||
type bindingSection struct {
|
type bindingSection struct {
|
||||||
@ -26,14 +26,25 @@ type bindingSection struct {
|
|||||||
bindings []*gui.Binding
|
bindings []*gui.Binding
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func CommandToRun() string {
|
||||||
|
return "go run scripts/cheatsheet/main.go generate"
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDir() string {
|
||||||
|
return integration.GetRootDirectory() + "/docs/keybindings"
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateAtDir(cheatsheetDir string) {
|
||||||
|
os.Setenv("LANG", "en")
|
||||||
|
|
||||||
translationSetsByLang := i18n.GetTranslationSets()
|
translationSetsByLang := i18n.GetTranslationSets()
|
||||||
mConfig := config.NewDummyAppConfig()
|
mConfig := config.NewDummyAppConfig()
|
||||||
|
|
||||||
for lang := range translationSetsByLang {
|
for lang := range translationSetsByLang {
|
||||||
os.Setenv("LC_ALL", lang)
|
os.Setenv("LC_ALL", lang)
|
||||||
mApp, _ := app.NewApp(mConfig, "")
|
mApp, _ := app.NewApp(mConfig, "")
|
||||||
file, err := os.Create(getProjectRoot() + "/docs/keybindings/Keybindings_" + lang + ".md")
|
path := cheatsheetDir + "/Keybindings_" + lang + ".md"
|
||||||
|
file, err := os.Create(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -41,11 +52,15 @@ func main() {
|
|||||||
bindingSections := getBindingSections(mApp)
|
bindingSections := getBindingSections(mApp)
|
||||||
content := formatSections(mApp.Tr, bindingSections)
|
content := formatSections(mApp.Tr, bindingSections)
|
||||||
content = fmt.Sprintf("# This file is auto-generated. To update, make the changes in the "+
|
content = fmt.Sprintf("# This file is auto-generated. To update, make the changes in the "+
|
||||||
"pkg/i18n directory and then run `go run scripts/generate_cheatsheet.go` from the project root.\n\n%s", content)
|
"pkg/i18n directory and then run `%s` from the project root.\n\n%s", CommandToRun(), content)
|
||||||
writeString(file, content)
|
writeString(file, content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Generate() {
|
||||||
|
generateAtDir(GetDir())
|
||||||
|
}
|
||||||
|
|
||||||
func writeString(file *os.File, str string) {
|
func writeString(file *os.File, str string) {
|
||||||
_, err := file.WriteString(str)
|
_, err := file.WriteString(str)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -248,11 +263,3 @@ func formatSections(tr *i18n.TranslationSet, bindingSections []*bindingSection)
|
|||||||
|
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
func getProjectRoot() string {
|
|
||||||
dir, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return strings.Split(dir, "lazygit")[0] + "lazygit"
|
|
||||||
}
|
|
27
scripts/cheatsheet/main.go
Normal file
27
scripts/cheatsheet/main.go
Normal file
@ -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'")
|
||||||
|
}
|
||||||
|
}
|
@ -1,63 +0,0 @@
|
|||||||
// call from project root with
|
|
||||||
// go run scripts/push_new_patch/main.go
|
|
||||||
|
|
||||||
// goreleaser expects a $GITHUB_TOKEN env variable to be defined
|
|
||||||
// in order to push the release got github
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/secureexec"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
version, err := ioutil.ReadFile("VERSION")
|
|
||||||
if err != nil {
|
|
||||||
log.Panicln(err.Error())
|
|
||||||
}
|
|
||||||
stringVersion := string(version)
|
|
||||||
fmt.Println("VERSION was " + stringVersion)
|
|
||||||
|
|
||||||
runCommand("git", "pull")
|
|
||||||
|
|
||||||
splitVersion := strings.Split(stringVersion, ".")
|
|
||||||
patch := splitVersion[len(splitVersion)-1]
|
|
||||||
newPatch, _ := strconv.Atoi(patch)
|
|
||||||
splitVersion[len(splitVersion)-1] = strconv.FormatInt(int64(newPatch)+1, 10)
|
|
||||||
newVersion := strings.Join(splitVersion, ".")
|
|
||||||
|
|
||||||
err = ioutil.WriteFile("VERSION", []byte(newVersion), 0644)
|
|
||||||
if err != nil {
|
|
||||||
log.Panicln(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
runCommand("git", "add", "VERSION")
|
|
||||||
runCommand("git", "commit", "-m", "bump version to "+newVersion, "--", "VERSION")
|
|
||||||
runCommand("git", "push")
|
|
||||||
runCommand("git", "tag", newVersion)
|
|
||||||
runCommand("git", "push", "origin", newVersion)
|
|
||||||
runCommand("goreleaser", "--rm-dist")
|
|
||||||
runCommand("rm", "-rf", "dist")
|
|
||||||
}
|
|
||||||
|
|
||||||
func runCommand(args ...string) {
|
|
||||||
fmt.Println(strings.Join(args, " "))
|
|
||||||
cmd := secureexec.Command(args[0], args[1:]...)
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
err := cmd.Start()
|
|
||||||
if err != nil {
|
|
||||||
panic(err.Error())
|
|
||||||
}
|
|
||||||
err = cmd.Wait()
|
|
||||||
if err != nil {
|
|
||||||
panic(err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
1
vendor/modules.txt
vendored
1
vendor/modules.txt
vendored
@ -206,6 +206,7 @@ github.com/mitchellh/go-homedir
|
|||||||
# github.com/onsi/gomega v1.7.1
|
# github.com/onsi/gomega v1.7.1
|
||||||
## explicit
|
## explicit
|
||||||
# github.com/pmezard/go-difflib v1.0.0
|
# github.com/pmezard/go-difflib v1.0.0
|
||||||
|
## explicit
|
||||||
github.com/pmezard/go-difflib/difflib
|
github.com/pmezard/go-difflib/difflib
|
||||||
# github.com/rivo/uniseg v0.2.0
|
# github.com/rivo/uniseg v0.2.0
|
||||||
github.com/rivo/uniseg
|
github.com/rivo/uniseg
|
||||||
|
Loading…
Reference in New Issue
Block a user