| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- /*
- Copyright 2020 Docker, Inc.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
- package cmd
- import (
- "fmt"
- "strings"
- "github.com/spf13/cobra"
- "github.com/docker/api/cli/cmd/mobyflags"
- "github.com/docker/api/cli/mobycli"
- )
- const cliVersion = "0.1.1"
- // 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,
- }
- // define flags for backward compatibility with com.docker.cli
- flags := cmd.Flags()
- flags.String("format", "", "Format the output using the given Go template")
- flags.String("kubeconfig", "", "Kubernetes config file")
- mobyflags.AddMobyFlagsForRetrocompatibility(flags)
- return cmd
- }
- func runVersion(cmd *cobra.Command, args []string) error {
- versionResult, _ := mobycli.ExecSilent(cmd.Context())
- // 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 {
- return mobycli.ExecCmd(cmd)
- }
- var s string = string(versionResult)
- fmt.Print(strings.Replace(s, "\n Version:", "\n Azure integration "+cliVersion+"\n Version:", 1))
- return nil
- }
|