mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
use go's own git version info
This commit is contained in:
parent
14cb013f5d
commit
e68554cee9
3 changed files with 41 additions and 2 deletions
33
main.go
33
main.go
|
|
@ -6,18 +6,23 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"runtime/debug"
|
||||||
|
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
"github.com/integrii/flaggy"
|
"github.com/integrii/flaggy"
|
||||||
"github.com/jesseduffield/lazydocker/pkg/app"
|
"github.com/jesseduffield/lazydocker/pkg/app"
|
||||||
"github.com/jesseduffield/lazydocker/pkg/config"
|
"github.com/jesseduffield/lazydocker/pkg/config"
|
||||||
|
"github.com/jesseduffield/lazydocker/pkg/utils"
|
||||||
"github.com/jesseduffield/yaml"
|
"github.com/jesseduffield/yaml"
|
||||||
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const DEFAULT_VERSION = "unversioned"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
commit string
|
commit string
|
||||||
version = "unversioned"
|
version = DEFAULT_VERSION
|
||||||
date string
|
date string
|
||||||
buildSource = "unknown"
|
buildSource = "unknown"
|
||||||
|
|
||||||
|
|
@ -27,6 +32,8 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
updateBuildInfo()
|
||||||
|
|
||||||
info := fmt.Sprintf(
|
info := fmt.Sprintf(
|
||||||
"%s\nDate: %s\nBuildSource: %s\nCommit: %s\nOS: %s\nArch: %s",
|
"%s\nDate: %s\nBuildSource: %s\nCommit: %s\nOS: %s\nArch: %s",
|
||||||
version,
|
version,
|
||||||
|
|
@ -93,3 +100,27 @@ func main() {
|
||||||
log.Fatal(fmt.Sprintf("%s\n\n%s", app.Tr.ErrorOccurred, stackTrace))
|
log.Fatal(fmt.Sprintf("%s\n\n%s", app.Tr.ErrorOccurred, stackTrace))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateBuildInfo() {
|
||||||
|
if version == DEFAULT_VERSION {
|
||||||
|
if buildInfo, ok := debug.ReadBuildInfo(); ok {
|
||||||
|
revision, ok := lo.Find(buildInfo.Settings, func(setting debug.BuildSetting) bool {
|
||||||
|
return setting.Key == "vcs.revision"
|
||||||
|
})
|
||||||
|
if ok {
|
||||||
|
commit = revision.Value
|
||||||
|
// if lazydocker was built from source we'll show the version as the
|
||||||
|
// abbreviated commit hash
|
||||||
|
version = utils.SafeTruncate(revision.Value, 7)
|
||||||
|
}
|
||||||
|
|
||||||
|
// if version hasn't been set we assume that neither has the date
|
||||||
|
time, ok := lo.Find(buildInfo.Settings, func(setting debug.BuildSetting) bool {
|
||||||
|
return setting.Key == "vcs.time"
|
||||||
|
})
|
||||||
|
if ok {
|
||||||
|
date = time.Value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
||||||
g.Highlight = true
|
g.Highlight = true
|
||||||
width, height := g.Size()
|
width, height := g.Size()
|
||||||
|
|
||||||
information := "lazydocker " + gui.Config.Version
|
information := gui.Config.Version
|
||||||
if gui.g.Mouse {
|
if gui.g.Mouse {
|
||||||
donate := color.New(color.FgMagenta, color.Underline).Sprint(gui.Tr.Donate)
|
donate := color.New(color.FgMagenta, color.Underline).Sprint(gui.Tr.Donate)
|
||||||
information = donate + " " + information
|
information = donate + " " + information
|
||||||
|
|
|
||||||
|
|
@ -379,3 +379,11 @@ func CloseMany(closers []io.Closer) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SafeTruncate(str string, limit int) string {
|
||||||
|
if len(str) > limit {
|
||||||
|
return str[0:limit]
|
||||||
|
} else {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue