47 lines
761 B
Go
47 lines
761 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
)
|
|
|
|
type VersionCommand struct {
|
|
*flag.FlagSet
|
|
fullVersion bool
|
|
}
|
|
|
|
var (
|
|
binaryVersion string
|
|
buildTime string
|
|
goVersion string
|
|
gitCommit string
|
|
)
|
|
|
|
func NewVersionCommand() *VersionCommand {
|
|
vc := VersionCommand{
|
|
FlagSet: flag.NewFlagSet("version", flag.ExitOnError),
|
|
}
|
|
|
|
vc.BoolVar(&vc.fullVersion, "full", false, "prints the full version")
|
|
|
|
return &vc
|
|
}
|
|
|
|
func (v *VersionCommand) Run() error {
|
|
var version string
|
|
if v.fullVersion {
|
|
fullVersionFmt := `Spruce
|
|
Version: %s
|
|
Git commit: %s
|
|
Go version: %s
|
|
Build date: %s
|
|
`
|
|
|
|
version = fmt.Sprintf(fullVersionFmt, binaryVersion, gitCommit, goVersion, buildTime)
|
|
} else {
|
|
version = binaryVersion + "\n"
|
|
}
|
|
|
|
fmt.Print(version)
|
|
return nil
|
|
}
|