mirror of https://github.com/docker/cli.git
Fold `dockerPreRun` into `DockerCli.Initialize`
All of the current callers follow the pattern: dockerPreRun(opts) err := dockerCli.Initialize(opts) ... So there is no semantic change into merging the content of `dockerPreRun` into the head of `Initialize`. I'm about to add a new caller outside of the `cmd/docker` package and this seems preferable exporting `DockerPreRun`. Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
parent
a17f67e456
commit
158a766886
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/docker/cli/cli/context/docker"
|
||||
kubcontext "github.com/docker/cli/cli/context/kubernetes"
|
||||
"github.com/docker/cli/cli/context/store"
|
||||
"github.com/docker/cli/cli/debug"
|
||||
cliflags "github.com/docker/cli/cli/flags"
|
||||
manifeststore "github.com/docker/cli/cli/manifest/store"
|
||||
registryclient "github.com/docker/cli/cli/registry/client"
|
||||
|
@ -177,6 +178,16 @@ func (cli *DockerCli) RegistryClient(allowInsecure bool) registryclient.Registry
|
|||
// Initialize the dockerCli runs initialization that must happen after command
|
||||
// line flags are parsed.
|
||||
func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions) error {
|
||||
cliflags.SetLogLevel(opts.Common.LogLevel)
|
||||
|
||||
if opts.ConfigDir != "" {
|
||||
cliconfig.SetDir(opts.ConfigDir)
|
||||
}
|
||||
|
||||
if opts.Common.Debug {
|
||||
debug.Enable()
|
||||
}
|
||||
|
||||
cli.configFile = cliconfig.LoadDefaultConfigFile(cli.err)
|
||||
var err error
|
||||
cli.contextStore = store.New(cliconfig.ContextStoreDir(), cli.contextStoreConfig)
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/cli/cli/command/commands"
|
||||
cliconfig "github.com/docker/cli/cli/config"
|
||||
"github.com/docker/cli/cli/debug"
|
||||
cliflags "github.com/docker/cli/cli/flags"
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/docker/docker/client"
|
||||
|
@ -36,7 +35,6 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
// flags must be the top-level command flags, not cmd.Flags()
|
||||
opts.Common.SetDefaultOptions(flags)
|
||||
dockerPreRun(opts)
|
||||
if err := dockerCli.Initialize(opts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -144,7 +142,6 @@ func initializeDockerCli(dockerCli *command.DockerCli, flags *pflag.FlagSet, opt
|
|||
// when using --help, PersistentPreRun is not called, so initialization is needed.
|
||||
// flags must be the top-level command flags, not cmd.Flags()
|
||||
opts.Common.SetDefaultOptions(flags)
|
||||
dockerPreRun(opts)
|
||||
return dockerCli.Initialize(opts)
|
||||
}
|
||||
|
||||
|
@ -193,18 +190,6 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
func dockerPreRun(opts *cliflags.ClientOptions) {
|
||||
cliflags.SetLogLevel(opts.Common.LogLevel)
|
||||
|
||||
if opts.ConfigDir != "" {
|
||||
cliconfig.SetDir(opts.ConfigDir)
|
||||
}
|
||||
|
||||
if opts.Common.Debug {
|
||||
debug.Enable()
|
||||
}
|
||||
}
|
||||
|
||||
type versionDetails interface {
|
||||
Client() client.APIClient
|
||||
ClientInfo() command.ClientInfo
|
||||
|
|
Loading…
Reference in New Issue