Fix: --version formatting

This commit is contained in:
Yoann La Cancellera
2023-09-14 10:14:10 +02:00
parent bbba087a83
commit 5638387713

View File

@@ -12,13 +12,20 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
// ldflags const (
var ( toolname = "pt-galera-log-explainer"
version string
commit string
date string
) )
// We do not set anything here, these variables are defined by the Makefile
var (
Build string //nolint
GoVersion string //nolint
Version string //nolint
Commit string //nolint
)
var buildInfo = fmt.Sprintf("%s\nVersion %s\nBuild: %s using %s\nCommit: %s\n", toolname, Version, Build, GoVersion, Commit)
var CLI struct { var CLI struct {
NoColor bool NoColor bool
Since *time.Time `help:"Only list events after this date, format: 2023-01-23T03:53:40Z (RFC3339)"` Since *time.Time `help:"Only list events after this date, format: 2023-01-23T03:53:40Z (RFC3339)"`
@@ -33,28 +40,22 @@ var CLI struct {
Sed sed `cmd:""` Sed sed `cmd:""`
Ctx ctx `cmd:""` Ctx ctx `cmd:""`
RegexList regexList `cmd:""` RegexList regexList `cmd:""`
Version versioncmd `cmd:""`
Conflicts conflicts `cmd:""` Conflicts conflicts `cmd:""`
Version kong.VersionFlag
GrepCmd string `help:"'grep' command path. Could need to be set to 'ggrep' for darwin systems" default:"grep"` GrepCmd string `help:"'grep' command path. Could need to be set to 'ggrep' for darwin systems" default:"grep"`
GrepArgs string `help:"'grep' arguments. perl regexp (-P) is necessary. -o will break the tool" default:"-P"` GrepArgs string `help:"'grep' arguments. perl regexp (-P) is necessary. -o will break the tool" default:"-P"`
} }
type versioncmd struct{}
func (v *versioncmd) Help() string {
return ""
}
func (v *versioncmd) Run() error {
fmt.Printf("version: %s, commit:%s, built at %s\n", version, commit, date)
return nil
}
func main() { func main() {
ctx := kong.Parse(&CLI, ctx := kong.Parse(&CLI,
kong.Name("pt-galera-log-explainer"), kong.Name(toolname),
kong.Description("An utility to merge and help analyzing Galera logs"), kong.Description("An utility to merge and help analyzing Galera logs"),
kong.UsageOnError(), kong.UsageOnError(),
kong.Vars{
"version": buildInfo,
},
) )
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix zerolog.TimeFieldFormat = zerolog.TimeFormatUnix