2020-06-12 17:54:14 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2020-06-17 17:57:44 +02:00
|
|
|
"github.com/docker/api/cli/mobycli"
|
2020-06-12 17:54:14 +02:00
|
|
|
)
|
|
|
|
|
2020-06-18 12:25:10 +02:00
|
|
|
const cliVersion = "0.1.1"
|
2020-06-12 17:54:14 +02:00
|
|
|
|
|
|
|
// VersionCommand command to display version
|
|
|
|
func VersionCommand() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "version",
|
|
|
|
Short: "Show the Docker version information",
|
|
|
|
Args: cobra.MaximumNArgs(0),
|
|
|
|
RunE: runVersion,
|
|
|
|
}
|
2020-06-17 17:57:44 +02:00
|
|
|
// define flags for backward compatibility with com.docker.cli
|
2020-06-12 17:54:14 +02:00
|
|
|
flags := cmd.Flags()
|
|
|
|
flags.String("format", "", "Format the output using the given Go template")
|
|
|
|
flags.String("kubeconfig", "", "Kubernetes config file")
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func runVersion(cmd *cobra.Command, args []string) error {
|
2020-06-17 17:57:44 +02:00
|
|
|
versionResult, _ := mobycli.ExecSilent(cmd.Context())
|
2020-06-12 17:54:14 +02:00
|
|
|
// we don't want to fail on error, there is an error if the engine is not available but it displays client version info
|
|
|
|
// Still, technically the [] byte versionResult could be nil, just let the original command display what it has to display
|
|
|
|
if versionResult == nil {
|
2020-06-17 17:57:44 +02:00
|
|
|
return mobycli.ExecCmd(cmd)
|
2020-06-12 17:54:14 +02:00
|
|
|
}
|
|
|
|
var s string = string(versionResult)
|
|
|
|
fmt.Print(strings.Replace(s, "\n Version:", "\n Azure integration "+cliVersion+"\n Version:", 1))
|
|
|
|
return nil
|
|
|
|
}
|