Allow running docker -v or --version even if context is not default

This commit is contained in:
Guillaume Tardif 2020-06-23 15:13:43 +02:00
parent 4197ef8b68
commit fa8b911cd8
3 changed files with 15 additions and 2 deletions

View File

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

View File

@ -26,5 +26,6 @@ type GlobalOpts struct {
apicontext.ContextFlags apicontext.ContextFlags
cliconfig.ConfigFlags cliconfig.ConfigFlags
Debug bool Debug bool
Version bool
Host string Host string
} }

View File

@ -226,6 +226,14 @@ func defaultEndpoint() string {
return "unix:///var/run/docker.sock" 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() { func (s *E2eSuite) TestDisplaysAdditionalLineInDockerVersion() {
output := s.NewDockerCommand("version").ExecOrDie() output := s.NewDockerCommand("version").ExecOrDie()
Expect(output).To(ContainSubstring("Azure integration")) Expect(output).To(ContainSubstring("Azure integration"))