mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-21 23:01:03 +00:00
Merge pull request #374 from gusandrioli/check-cheatsheet-is-up-to-date
This commit is contained in:
commit
38959a0e2b
15 changed files with 197 additions and 85 deletions
28
.github/workflows/ci.yml
vendored
28
.github/workflows/ci.yml
vendored
|
|
@ -66,6 +66,34 @@ jobs:
|
|||
- name: Build darwin binary
|
||||
run: |
|
||||
GOOS=darwin go build
|
||||
check-codebase:
|
||||
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.18.x
|
||||
- name: Cache build
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: |
|
||||
~/.cache/go-build
|
||||
~/go/pkg/mod
|
||||
key: ${{runner.os}}-go-${{hashFiles('**/go.sum')}}-build
|
||||
restore-keys: |
|
||||
${{runner.os}}-go-
|
||||
- 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: |
|
||||
go mod vendor && git diff --exit-code || (echo "Unexpected change to vendor directory. Run 'go mod vendor' locally and commit the changes" && exit 1)
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
|
|
|
|||
|
|
@ -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._
|
||||
|
||||
# Lazydocker menü
|
||||
|
||||
|
|
|
|||
|
|
@ -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._
|
||||
|
||||
# Lazydocker menu
|
||||
|
||||
|
|
|
|||
|
|
@ -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._
|
||||
|
||||
# Lazydocker menu
|
||||
|
||||
|
|
|
|||
|
|
@ -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._
|
||||
|
||||
# Lazydocker menu
|
||||
|
||||
|
|
|
|||
|
|
@ -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._
|
||||
|
||||
# Lazydocker menü
|
||||
|
||||
|
|
|
|||
5
go.mod
5
go.mod
|
|
@ -9,18 +9,18 @@ require (
|
|||
github.com/docker/docker v20.10.15+incompatible
|
||||
github.com/fatih/color v1.7.0
|
||||
github.com/go-errors/errors v1.4.2
|
||||
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
|
||||
github.com/gookit/color v1.5.0
|
||||
github.com/imdario/mergo v0.3.8
|
||||
github.com/integrii/flaggy v1.4.0
|
||||
github.com/jesseduffield/asciigraph v0.0.0-20190605104717-6d88e39309ee
|
||||
github.com/jesseduffield/gocui v0.3.1-0.20220417002912-bce22fd599f6
|
||||
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10
|
||||
github.com/jesseduffield/lazycore v0.0.0-20221009164442-17c8b878c316
|
||||
github.com/jesseduffield/lazycore v0.0.0-20221010211550-2c30efd18b93
|
||||
github.com/jesseduffield/yaml v0.0.0-20190702115811-b900b7e08b56
|
||||
github.com/mattn/go-runewidth v0.0.13
|
||||
github.com/mcuadros/go-lookup v0.0.0-20171110082742-5650f26be767
|
||||
github.com/mgutz/str v1.2.0
|
||||
github.com/pmezard/go-difflib v1.0.0
|
||||
github.com/samber/lo v1.31.0
|
||||
github.com/sirupsen/logrus v1.4.2
|
||||
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad
|
||||
|
|
@ -48,7 +48,6 @@ require (
|
|||
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
|
||||
github.com/opencontainers/image-spec v1.0.1 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
|
||||
golang.org/x/exp v0.0.0-20220428152302-39d4317da171 // indirect
|
||||
|
|
|
|||
6
go.sum
6
go.sum
|
|
@ -33,8 +33,6 @@ github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxI
|
|||
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
|
||||
github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
|
||||
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 h1:zN2lZNZRflqFyxVaTIU61KNKQ9C0055u9CAfpmqUvo4=
|
||||
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3/go.mod h1:nPpo7qLxd6XL3hWJG/O60sR8ZKfMCiIoNap5GvD12KU=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
|
|
@ -54,8 +52,8 @@ github.com/jesseduffield/gocui v0.3.1-0.20220417002912-bce22fd599f6 h1:Fmay0Lz21
|
|||
github.com/jesseduffield/gocui v0.3.1-0.20220417002912-bce22fd599f6/go.mod h1:znJuCDnF2Ph40YZSlBwdX/4GEofnIoWLGdT4mK5zRAU=
|
||||
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10 h1:jmpr7KpX2+2GRiE91zTgfq49QvgiqB0nbmlwZ8UnOx0=
|
||||
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10/go.mod h1:aA97kHeNA+sj2Hbki0pvLslmE4CbDyhBeSSTUUnOuVo=
|
||||
github.com/jesseduffield/lazycore v0.0.0-20221009164442-17c8b878c316 h1:UzTg0utG+cLS94Qjb/ZFDzfMeZDFXErSbNgJOyj70EA=
|
||||
github.com/jesseduffield/lazycore v0.0.0-20221009164442-17c8b878c316/go.mod h1:qxN4mHOAyeIDLP7IK7defgPClM/z1Kze8VVQiaEjzsQ=
|
||||
github.com/jesseduffield/lazycore v0.0.0-20221010211550-2c30efd18b93 h1:zY7ymCjXC7fZeJVXDpiicYx6c2YFgvsdZSOdch2f7gU=
|
||||
github.com/jesseduffield/lazycore v0.0.0-20221010211550-2c30efd18b93/go.mod h1:qxN4mHOAyeIDLP7IK7defgPClM/z1Kze8VVQiaEjzsQ=
|
||||
github.com/jesseduffield/yaml v0.0.0-20190702115811-b900b7e08b56 h1:33wSxJWU/f2TAozHYtJ8zqBxEnEVYM+22moLoiAkxvg=
|
||||
github.com/jesseduffield/yaml v0.0.0-20190702115811-b900b7e08b56/go.mod h1:FZJBwOhE+RXz8EVZfY+xnbCw2cVOwxlK3/aIi581z/s=
|
||||
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
// The content of this generated file is a keybindings cheatsheet.
|
||||
//
|
||||
// To generate cheatsheet in english run:
|
||||
// LANG=en go run scripts/generate_cheatsheet.go
|
||||
// LANG=en go run scripts/cheatsheet/main.go generate
|
||||
|
||||
package main
|
||||
package cheatsheet
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
@ -20,7 +20,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
generateCheatsheetCmd = "go run scripts/generate_cheatsheet.go"
|
||||
generateCheatsheetCmd = "go run scripts/cheatsheet/main.go generate"
|
||||
)
|
||||
|
||||
type bindingSection struct {
|
||||
|
|
@ -28,7 +28,11 @@ type bindingSection struct {
|
|||
bindings []*gui.Binding
|
||||
}
|
||||
|
||||
func main() {
|
||||
func Generate() {
|
||||
generateAtDir(GetKeybindingsDir())
|
||||
}
|
||||
|
||||
func generateAtDir(dir string) {
|
||||
mConfig, err := config.NewAppConfig("lazydocker", "", "", "", "", true, nil, "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
@ -37,7 +41,8 @@ func main() {
|
|||
for lang := range i18n.GetTranslationSets() {
|
||||
os.Setenv("LC_ALL", lang)
|
||||
mApp, _ := app.NewApp(mConfig)
|
||||
file, err := os.Create("./docs/keybindings/Keybindings_" + lang + ".md")
|
||||
|
||||
file, err := os.Create(dir + "/Keybindings_" + lang + ".md")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
87
pkg/cheatsheet/validate.go
Normal file
87
pkg/cheatsheet/validate.go
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
package cheatsheet
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
|
||||
"github.com/jesseduffield/lazycore/pkg/utils"
|
||||
"github.com/pmezard/go-difflib/difflib"
|
||||
)
|
||||
|
||||
func Check() {
|
||||
dir := GetKeybindingsDir()
|
||||
tmpDir := filepath.Join(os.TempDir(), "lazydocker_cheatsheet")
|
||||
|
||||
err := os.RemoveAll(tmpDir)
|
||||
if err != nil {
|
||||
log.Fatalf("Error occurred while checking if cheatsheets are up to date: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
if err = os.Mkdir(tmpDir, 0o700); err != nil {
|
||||
log.Fatalf("Error occurred while checking if cheatsheets are up to date: %v", err)
|
||||
}
|
||||
|
||||
generateAtDir(tmpDir)
|
||||
|
||||
actualContent := obtainContent(dir)
|
||||
expectedContent := obtainContent(tmpDir)
|
||||
|
||||
if expectedContent == "" {
|
||||
log.Fatal("empty expected content")
|
||||
}
|
||||
|
||||
if actualContent != expectedContent {
|
||||
if err := difflib.WriteUnifiedDiff(os.Stdout, difflib.UnifiedDiff{
|
||||
A: difflib.SplitLines(expectedContent),
|
||||
B: difflib.SplitLines(actualContent),
|
||||
FromFile: "Expected",
|
||||
FromDate: "",
|
||||
ToFile: "Actual",
|
||||
ToDate: "",
|
||||
Context: 1,
|
||||
}); 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",
|
||||
generateCheatsheetCmd,
|
||||
)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Println("\nCheatsheets are up to date")
|
||||
}
|
||||
|
||||
func GetKeybindingsDir() string {
|
||||
return utils.GetLazyRootDirectory() + "/docs/keybindings"
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
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/lazydocker/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'")
|
||||
}
|
||||
}
|
||||
20
vendor/github.com/golang-collections/collections/LICENSE
generated
vendored
20
vendor/github.com/golang-collections/collections/LICENSE
generated
vendored
|
|
@ -1,20 +0,0 @@
|
|||
Copyright (c) 2012 Caleb Doxsey
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
44
vendor/github.com/golang-collections/collections/stack/stack.go
generated
vendored
44
vendor/github.com/golang-collections/collections/stack/stack.go
generated
vendored
|
|
@ -1,44 +0,0 @@
|
|||
package stack
|
||||
|
||||
type (
|
||||
Stack struct {
|
||||
top *node
|
||||
length int
|
||||
}
|
||||
node struct {
|
||||
value interface{}
|
||||
prev *node
|
||||
}
|
||||
)
|
||||
// Create a new stack
|
||||
func New() *Stack {
|
||||
return &Stack{nil,0}
|
||||
}
|
||||
// Return the number of items in the stack
|
||||
func (this *Stack) Len() int {
|
||||
return this.length
|
||||
}
|
||||
// View the top item on the stack
|
||||
func (this *Stack) Peek() interface{} {
|
||||
if this.length == 0 {
|
||||
return nil
|
||||
}
|
||||
return this.top.value
|
||||
}
|
||||
// Pop the top item of the stack and return it
|
||||
func (this *Stack) Pop() interface{} {
|
||||
if this.length == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
n := this.top
|
||||
this.top = n.prev
|
||||
this.length--
|
||||
return n.value
|
||||
}
|
||||
// Push a value onto the top of the stack
|
||||
func (this *Stack) Push(value interface{}) {
|
||||
n := &node{value,this.top}
|
||||
this.top = n
|
||||
this.length++
|
||||
}
|
||||
35
vendor/github.com/jesseduffield/lazycore/pkg/utils/utils.go
generated
vendored
35
vendor/github.com/jesseduffield/lazycore/pkg/utils/utils.go
generated
vendored
|
|
@ -1,5 +1,11 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// Min returns the minimum of two integers
|
||||
func Min(x, y int) int {
|
||||
if x < y {
|
||||
|
|
@ -8,9 +14,38 @@ func Min(x, y int) int {
|
|||
return y
|
||||
}
|
||||
|
||||
// Max returns the maximum of two integers
|
||||
func Max(x, y int) int {
|
||||
if x > y {
|
||||
return x
|
||||
}
|
||||
return y
|
||||
}
|
||||
|
||||
// GetLazyRootDirectory finds a lazy project root directory.
|
||||
//
|
||||
// It's used for cheatsheet scripts and integration tests. Not to be confused with finding the
|
||||
// root directory of _any_ random repo.
|
||||
func GetLazyRootDirectory() string {
|
||||
path, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for {
|
||||
_, err := os.Stat(filepath.Join(path, ".git"))
|
||||
if err == nil {
|
||||
return path
|
||||
}
|
||||
|
||||
if !os.IsNotExist(err) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
path = filepath.Dir(path)
|
||||
|
||||
if path == "/" {
|
||||
log.Fatal("must run in lazy project folder or child folder")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
5
vendor/modules.txt
vendored
5
vendor/modules.txt
vendored
|
|
@ -100,9 +100,6 @@ github.com/go-errors/errors
|
|||
# github.com/gogo/protobuf v1.3.1
|
||||
## explicit
|
||||
github.com/gogo/protobuf/proto
|
||||
# github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
|
||||
## explicit
|
||||
github.com/golang-collections/collections/stack
|
||||
# github.com/gookit/color v1.5.0
|
||||
## explicit; go 1.13
|
||||
github.com/gookit/color
|
||||
|
|
@ -121,7 +118,7 @@ github.com/jesseduffield/gocui
|
|||
# github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10
|
||||
## explicit; go 1.18
|
||||
github.com/jesseduffield/kill
|
||||
# github.com/jesseduffield/lazycore v0.0.0-20221009164442-17c8b878c316
|
||||
# github.com/jesseduffield/lazycore v0.0.0-20221010211550-2c30efd18b93
|
||||
## explicit; go 1.18
|
||||
github.com/jesseduffield/lazycore/pkg/boxlayout
|
||||
github.com/jesseduffield/lazycore/pkg/utils
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue