2018-03-01 07:10:04 +00:00
|
|
|
package version
|
2016-11-30 12:08:06 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
"text/template"
|
2016-12-30 08:21:13 +00:00
|
|
|
|
2019-06-17 09:48:05 +00:00
|
|
|
"github.com/containous/traefik/pkg/cli"
|
2019-03-15 08:42:03 +00:00
|
|
|
"github.com/containous/traefik/pkg/version"
|
2016-11-30 12:08:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var versionTemplate = `Version: {{.Version}}
|
|
|
|
Codename: {{.Codename}}
|
|
|
|
Go version: {{.GoVersion}}
|
|
|
|
Built: {{.BuildTime}}
|
|
|
|
OS/Arch: {{.Os}}/{{.Arch}}`
|
|
|
|
|
2018-03-01 07:10:04 +00:00
|
|
|
// NewCmd builds a new Version command
|
2019-06-17 09:48:05 +00:00
|
|
|
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 {
|
2016-11-30 12:08:06 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-05-26 15:03:14 +00:00
|
|
|
fmt.Print("\n")
|
2016-11-30 12:08:06 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-01 07:10:04 +00:00
|
|
|
// GetPrint write Printable version
|
|
|
|
func GetPrint(wr io.Writer) error {
|
2016-11-30 12:08:06 +00:00
|
|
|
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)
|
|
|
|
}
|