Browse Source

Merge pull request #266 from docker/docker-v-context

Allow running `docker -v` or `--version` even if context is not default
Guillaume Tardif 5 years ago
parent
commit
76c062b755
3 changed files with 15 additions and 2 deletions
  1. 4 0
      cli/main.go
  2. 3 2
      cli/options/options.go
  3. 8 0
      tests/e2e/e2e_test.go

+ 4 - 0
cli/main.go

@@ -124,6 +124,7 @@ func main() {
 	root.PersistentFlags().StringVarP(&opts.Host, "host", "H", "", "Daemon socket(s) to connect to")
 	opts.AddConfigFlags(root.PersistentFlags())
 	opts.AddContextFlags(root.PersistentFlags())
+	root.Flags().BoolVarP(&opts.Version, "version", "v", false, "Print version information and quit")
 
 	// populate the opts with the global flags
 	_ = root.PersistentFlags().Parse(os.Args[1:])
@@ -137,6 +138,9 @@ func main() {
 	if opts.Host != "" {
 		mobycli.ExecRegardlessContext(ctx)
 	}
+	if opts.Version {
+		mobycli.ExecRegardlessContext(ctx)
+	}
 
 	if opts.Config == "" {
 		fatal(errors.New("config path cannot be empty"))

+ 3 - 2
cli/options/options.go

@@ -25,6 +25,7 @@ import (
 type GlobalOpts struct {
 	apicontext.ContextFlags
 	cliconfig.ConfigFlags
-	Debug bool
-	Host  string
+	Debug   bool
+	Version bool
+	Host    string
 }

+ 8 - 0
tests/e2e/e2e_test.go

@@ -226,6 +226,14 @@ func defaultEndpoint() string {
 	return "unix:///var/run/docker.sock"
 }
 
+func (s *E2eSuite) TestExecMobyIfUsingversionFlag() {
+	s.NewDockerCommand("context", "create", "example", "test-example").ExecOrDie()
+	s.NewDockerCommand("context", "use", "test-example").ExecOrDie()
+	output, err := s.NewDockerCommand("-v").Exec()
+	Expect(err).To(BeNil())
+	Expect(output).To(ContainSubstring("Docker version"))
+}
+
 func (s *E2eSuite) TestDisplaysAdditionalLineInDockerVersion() {
 	output := s.NewDockerCommand("version").ExecOrDie()
 	Expect(output).To(ContainSubstring("Azure integration"))