diff options
author | Gustavo Andrioli <gusaandrioli@gmail.com> | 2022-10-15 13:47:55 -0300 |
---|---|---|
committer | Gustavo Andrioli <gusaandrioli@gmail.com> | 2022-10-15 13:55:44 -0300 |
commit | 39e84e13f4ed80ff94b2a1fc6e66685c24fa6d1e (patch) | |
tree | f640b2a2e78f8485dbc9a6d504c1366e19c67224 /vendor | |
parent | 05089b9a9a26502c2c4b92f20e60979ce02bca67 (diff) |
Use lazycore utils: Clamp and GetLazyRootDirectory
Diffstat (limited to 'vendor')
-rw-r--r-- | vendor/github.com/jesseduffield/lazycore/pkg/utils/utils.go | 45 | ||||
-rw-r--r-- | vendor/modules.txt | 2 |
2 files changed, 46 insertions, 1 deletions
diff --git a/vendor/github.com/jesseduffield/lazycore/pkg/utils/utils.go b/vendor/github.com/jesseduffield/lazycore/pkg/utils/utils.go index 9fa933762..06d828e42 100644 --- a/vendor/github.com/jesseduffield/lazycore/pkg/utils/utils.go +++ b/vendor/github.com/jesseduffield/lazycore/pkg/utils/utils.go @@ -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,48 @@ 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 } + +// Clamp returns a value x restricted between min and max +func Clamp(x int, min int, max int) int { + if x < min { + return min + } else if x > max { + return max + } + return x +} + +// 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") + } + } +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 97c89ac60..133f7501c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -178,7 +178,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-20221012050358-03d2e40243c5 ## explicit; go 1.18 github.com/jesseduffield/lazycore/pkg/boxlayout github.com/jesseduffield/lazycore/pkg/utils |