mirror of https://github.com/docker/compose.git
version command adding azure integration beta version in textual output
This commit is contained in:
parent
d9b4564533
commit
376a4b671c
|
@ -6,10 +6,11 @@ import (
|
|||
|
||||
"github.com/docker/api/context/store"
|
||||
|
||||
_ "github.com/docker/api/example"
|
||||
"github.com/docker/api/tests/framework"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
_ "github.com/docker/api/example"
|
||||
"github.com/docker/api/tests/framework"
|
||||
)
|
||||
|
||||
type PsSuite struct {
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/docker/api/cli/dockerclassic"
|
||||
)
|
||||
|
||||
const cliVersion = "0.1-beta"
|
||||
|
||||
// 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 docker-classic
|
||||
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 {
|
||||
versionResult, _ := dockerclassic.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 dockerclassic.ExecCmd(cmd)
|
||||
}
|
||||
var s string = string(versionResult)
|
||||
fmt.Print(strings.Replace(s, "\n Version:", "\n Azure integration "+cliVersion+"\n Version:", 1))
|
||||
return nil
|
||||
}
|
|
@ -57,3 +57,9 @@ func IsDefaultContextCommand(dockerCommand string) bool {
|
|||
contains := strings.Contains(output, "Usage:\tdocker "+dockerCommand)
|
||||
return contains
|
||||
}
|
||||
|
||||
// ExecSilent executes a command and do redirect output to stdOut, return output
|
||||
func ExecSilent(ctx context.Context) ([]byte, error) {
|
||||
cmd := exec.CommandContext(ctx, ClassicCliName, os.Args[1:]...)
|
||||
return cmd.CombinedOutput()
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@ var (
|
|||
"context": {},
|
||||
"login": {},
|
||||
"serve": {},
|
||||
"version": {},
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -119,6 +120,7 @@ func main() {
|
|||
cmd.RmCommand(),
|
||||
compose.Command(),
|
||||
login.Command(),
|
||||
cmd.VersionCommand(),
|
||||
)
|
||||
|
||||
helpFunc := root.HelpFunc()
|
||||
|
|
|
@ -141,6 +141,12 @@ func (s *E2eSuite) TestDisplayFriendlyErrorMessageForLegacyCommands() {
|
|||
Expect(err).NotTo(BeNil())
|
||||
}
|
||||
|
||||
func (s *E2eSuite) TestDisplaysAdditionalLineInDockerVersion() {
|
||||
output := s.NewDockerCommand("version").ExecOrDie()
|
||||
Expect(output).To(ContainSubstring(`Azure integration 0.1-beta
|
||||
Version: `))
|
||||
}
|
||||
|
||||
func (s *E2eSuite) TestMockBackend() {
|
||||
It("creates a new test context to hardcoded example backend", func() {
|
||||
s.NewDockerCommand("context", "create", "test-example", "example").ExecOrDie()
|
||||
|
|
Loading…
Reference in New Issue