version.go 1018 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package app
  2. import (
  3. "fmt"
  4. "os"
  5. "runtime"
  6. "text/template"
  7. "github.com/Sirupsen/logrus"
  8. "github.com/codegangsta/cli"
  9. "github.com/docker/libcompose/version"
  10. )
  11. var versionTemplate = `Version: {{.Version}} ({{.GitCommit}})
  12. Go version: {{.GoVersion}}
  13. Built: {{.BuildTime}}
  14. OS/Arch: {{.Os}}/{{.Arch}}`
  15. // Version prints the libcompose version number and additionnal informations.
  16. func Version(c *cli.Context) {
  17. if c.Bool("short") {
  18. fmt.Println(version.VERSION)
  19. return
  20. }
  21. tmpl, err := template.New("").Parse(versionTemplate)
  22. if err != nil {
  23. logrus.Fatal(err)
  24. }
  25. v := struct {
  26. Version string
  27. GitCommit string
  28. GoVersion string
  29. BuildTime string
  30. Os string
  31. Arch string
  32. }{
  33. Version: version.VERSION,
  34. GitCommit: version.GITCOMMIT,
  35. GoVersion: runtime.Version(),
  36. BuildTime: version.BUILDTIME,
  37. Os: runtime.GOOS,
  38. Arch: runtime.GOARCH,
  39. }
  40. if err := tmpl.Execute(os.Stdout, v); err != nil {
  41. logrus.Fatal(err)
  42. }
  43. fmt.Printf("\n")
  44. return
  45. }