MCPcopy Index your code
hub / github.com/docker/cli / newDockerCommand

Function newDockerCommand

cmd/docker/docker.go:136–193  ·  view source on GitHub ↗
(dockerCli *command.DockerCli)

Source from the content-addressed store, hash-verified

134}
135
136func newDockerCommand(dockerCli *command.DockerCli) *cli.TopLevelCommand {
137 var (
138 opts *cliflags.ClientOptions
139 helpCmd *cobra.Command
140 )
141
142 cmd := &cobra.Command{
143 Use: "docker [OPTIONS] COMMAND [ARG...]",
144 Short: "A self-sufficient runtime for containers",
145 SilenceUsage: true,
146 SilenceErrors: true,
147 TraverseChildren: true,
148 RunE: func(cmd *cobra.Command, args []string) error {
149 if len(args) == 0 {
150 return command.ShowHelp(dockerCli.Err())(cmd, args)
151 }
152 return fmt.Errorf("docker: unknown command: docker %s\n\nRun 'docker --help' for more information", args[0])
153 },
154 PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
155 return isSupported(cmd, dockerCli)
156 },
157 Version: fmt.Sprintf("%s, build %s", version.Version, version.GitCommit),
158 DisableFlagsInUseLine: true,
159 CompletionOptions: cobra.CompletionOptions{
160 DisableDefaultCmd: false,
161 HiddenDefaultCmd: true,
162 DisableDescriptions: os.Getenv("DOCKER_CLI_DISABLE_COMPLETION_DESCRIPTION") != "",
163 },
164 }
165
166 // Disable file-completion by default. Most commands and flags should not
167 // complete with filenames.
168 cmd.CompletionOptions.SetDefaultShellCompDirective(cobra.ShellCompDirectiveNoFileComp)
169
170 cmd.SetIn(dockerCli.In())
171 cmd.SetOut(dockerCli.Out())
172 cmd.SetErr(dockerCli.Err())
173
174 opts, helpCmd = cli.SetupRootCommand(cmd)
175
176 // TODO(thaJeztah): move configuring completion for these flags to where the flags are added.
177 _ = cmd.RegisterFlagCompletionFunc("context", completeContextNames(dockerCli))
178 _ = cmd.RegisterFlagCompletionFunc("log-level", completeLogLevels)
179
180 cmd.Flags().BoolP("version", "v", false, "Print version information and quit")
181 setFlagErrorFunc(dockerCli, cmd)
182
183 setupHelpCommand(dockerCli, cmd, helpCmd)
184 setHelpFunc(dockerCli, cmd)
185
186 cmd.SetOut(dockerCli.Out())
187 commands.AddCommands(cmd, dockerCli)
188
189 visitAll(cmd, setValidateArgs(dockerCli))
190
191 // flags must be the top-level command flags, not cmd.Flags()
192 return cli.NewTopLevelCommand(cmd, dockerCli, opts, cmd.Flags())
193}

Callers 7

TestBuildWithBuilderFunction · 0.85
TestBuildkitDisabledFunction · 0.85
TestBuilderBrokenFunction · 0.85
runDockerFunction · 0.85
TestClientDebugEnabledFunction · 0.85
runCliCommandFunction · 0.85

Calls 13

isSupportedFunction · 0.85
setFlagErrorFuncFunction · 0.85
setupHelpCommandFunction · 0.85
setHelpFuncFunction · 0.85
setValidateArgsFunction · 0.85
completeContextNamesFunction · 0.70
visitAllFunction · 0.70
ErrMethod · 0.65
SetInMethod · 0.65
InMethod · 0.65
OutMethod · 0.65
SetOutMethod · 0.45

Tested by 6

TestBuildWithBuilderFunction · 0.68
TestBuildkitDisabledFunction · 0.68
TestBuilderBrokenFunction · 0.68
TestClientDebugEnabledFunction · 0.68
runCliCommandFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…