version.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package cmd
  2. import (
  3. "fmt"
  4. "strings"
  5. "github.com/spf13/cobra"
  6. "github.com/docker/api/cli/dockerclassic"
  7. )
  8. const cliVersion = "1.0.0-beta"
  9. // VersionCommand command to display version
  10. func VersionCommand() *cobra.Command {
  11. cmd := &cobra.Command{
  12. Use: "version",
  13. Short: "Show the Docker version information",
  14. Args: cobra.MaximumNArgs(0),
  15. RunE: runVersion,
  16. }
  17. // define flags for backward compatibility with docker-classic
  18. flags := cmd.Flags()
  19. flags.String("format", "", "Format the output using the given Go template")
  20. flags.String("kubeconfig", "", "Kubernetes config file")
  21. return cmd
  22. }
  23. func runVersion(cmd *cobra.Command, args []string) error {
  24. versionResult, _ := dockerclassic.ExecSilent(cmd.Context())
  25. // we don't want to fail on error, there is an error if the engine is not available but it displays client version info
  26. // Still, technically the [] byte versionResult could be nil, just let the original command display what it has to display
  27. if versionResult == nil {
  28. return dockerclassic.ExecCmd(cmd)
  29. }
  30. var s string = string(versionResult)
  31. fmt.Print(strings.Replace(s, "\n Version:", "\n Azure integration "+cliVersion+"\n Version:", 1))
  32. return nil
  33. }