mirror of https://github.com/docker/cli.git
Merge pull request #1119 from silvin-lubecki/fix-help-docker-client-initialization
Check errors when initializing the docker client in the help command
This commit is contained in:
commit
aac3124794
|
@ -83,7 +83,9 @@ func setFlagErrorFunc(dockerCli *command.DockerCli, cmd *cobra.Command, flags *p
|
||||||
// is called.
|
// is called.
|
||||||
flagErrorFunc := cmd.FlagErrorFunc()
|
flagErrorFunc := cmd.FlagErrorFunc()
|
||||||
cmd.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
|
cmd.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
|
||||||
initializeDockerCli(dockerCli, flags, opts)
|
if err := initializeDockerCli(dockerCli, flags, opts); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := isSupported(cmd, dockerCli); err != nil {
|
if err := isSupported(cmd, dockerCli); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -94,7 +96,10 @@ func setFlagErrorFunc(dockerCli *command.DockerCli, cmd *cobra.Command, flags *p
|
||||||
func setHelpFunc(dockerCli *command.DockerCli, cmd *cobra.Command, flags *pflag.FlagSet, opts *cliflags.ClientOptions) {
|
func setHelpFunc(dockerCli *command.DockerCli, cmd *cobra.Command, flags *pflag.FlagSet, opts *cliflags.ClientOptions) {
|
||||||
defaultHelpFunc := cmd.HelpFunc()
|
defaultHelpFunc := cmd.HelpFunc()
|
||||||
cmd.SetHelpFunc(func(ccmd *cobra.Command, args []string) {
|
cmd.SetHelpFunc(func(ccmd *cobra.Command, args []string) {
|
||||||
initializeDockerCli(dockerCli, flags, opts)
|
if err := initializeDockerCli(dockerCli, flags, opts); err != nil {
|
||||||
|
ccmd.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
if err := isSupported(ccmd, dockerCli); err != nil {
|
if err := isSupported(ccmd, dockerCli); err != nil {
|
||||||
ccmd.Println(err)
|
ccmd.Println(err)
|
||||||
return
|
return
|
||||||
|
@ -123,7 +128,9 @@ func setValidateArgs(dockerCli *command.DockerCli, cmd *cobra.Command, flags *pf
|
||||||
|
|
||||||
cmdArgs := ccmd.Args
|
cmdArgs := ccmd.Args
|
||||||
ccmd.Args = func(cmd *cobra.Command, args []string) error {
|
ccmd.Args = func(cmd *cobra.Command, args []string) error {
|
||||||
initializeDockerCli(dockerCli, flags, opts)
|
if err := initializeDockerCli(dockerCli, flags, opts); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := isSupported(cmd, dockerCli); err != nil {
|
if err := isSupported(cmd, dockerCli); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -132,13 +139,15 @@ func setValidateArgs(dockerCli *command.DockerCli, cmd *cobra.Command, flags *pf
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func initializeDockerCli(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *cliflags.ClientOptions) {
|
func initializeDockerCli(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *cliflags.ClientOptions) error {
|
||||||
if dockerCli.Client() == nil { // when using --help, PersistentPreRun is not called, so initialization is needed.
|
if dockerCli.Client() != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// when using --help, PersistentPreRun is not called, so initialization is needed.
|
||||||
// flags must be the top-level command flags, not cmd.Flags()
|
// flags must be the top-level command flags, not cmd.Flags()
|
||||||
opts.Common.SetDefaultOptions(flags)
|
opts.Common.SetDefaultOptions(flags)
|
||||||
dockerPreRun(opts)
|
dockerPreRun(opts)
|
||||||
dockerCli.Initialize(opts)
|
return dockerCli.Initialize(opts)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// visitAll will traverse all commands from the root.
|
// visitAll will traverse all commands from the root.
|
||||||
|
|
Loading…
Reference in New Issue