traefik/cmd/version/version.go

61 lines
1.1 KiB
Go
Raw Normal View History

2018-03-01 07:10:04 +00:00
package version
import (
"fmt"
"io"
"os"
"runtime"
"text/template"
"github.com/traefik/paerser/cli"
2023-02-03 14:24:05 +00:00
"github.com/traefik/traefik/v3/pkg/version"
)
var versionTemplate = `Version: {{.Version}}
Codename: {{.Codename}}
Go version: {{.GoVersion}}
Built: {{.BuildTime}}
OS/Arch: {{.Os}}/{{.Arch}}`
2020-05-11 10:06:07 +00:00
// NewCmd builds a new Version command.
func NewCmd() *cli.Command {
return &cli.Command{
Name: "version",
Description: `Shows the current Traefik version.`,
Configuration: nil,
Run: func(_ []string) error {
2018-03-01 07:10:04 +00:00
if err := GetPrint(os.Stdout); err != nil {
return err
}
fmt.Print("\n")
return nil
},
}
}
2020-05-11 10:06:07 +00:00
// GetPrint write Printable version.
2018-03-01 07:10:04 +00:00
func GetPrint(wr io.Writer) error {
tmpl, err := template.New("").Parse(versionTemplate)
if err != nil {
return err
}
v := struct {
Version string
Codename string
GoVersion string
BuildTime string
Os string
Arch string
}{
Version: version.Version,
Codename: version.Codename,
GoVersion: runtime.Version(),
BuildTime: version.BuildDate,
Os: runtime.GOOS,
Arch: runtime.GOARCH,
}
return tmpl.Execute(wr, v)
}