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

Function setValidateArgs

cmd/docker/docker.go:295–320  ·  view source on GitHub ↗

The Args is handled by ValidateArgs in cobra, which does not allows a pre-hook. As a result, here we replace the existing Args validation func to a wrapper, where the wrapper will check to see if the feature is supported or not. The Args validation error will only be returned if the feature is suppo

(dockerCLI versionDetails)

Source from the content-addressed store, hash-verified

293// where the wrapper will check to see if the feature is supported or not.
294// The Args validation error will only be returned if the feature is supported.
295func setValidateArgs(dockerCLI versionDetails) func(*cobra.Command) {
296 return func(ccmd *cobra.Command) {
297 // if there is no tags for a command or any of its parent,
298 // there is no need to wrap the Args validation.
299 //
300 // FIXME(thaJeztah): can we memoize properties of the parent?
301 // visitAll traverses root -> all childcommands, and hasTags
302 // goes the reverse (cmd -> visit all parents), so we may
303 // end traversing two directions.
304 if !hasTags(ccmd) {
305 return
306 }
307
308 if ccmd.Args == nil {
309 return
310 }
311
312 cmdArgs := ccmd.Args
313 ccmd.Args = func(cmd *cobra.Command, args []string) error {
314 if err := isSupported(cmd, dockerCLI); err != nil {
315 return err
316 }
317 return cmdArgs(cmd, args)
318 }
319 }
320}
321
322func tryPluginRun(ctx context.Context, dockerCli command.Cli, cmd *cobra.Command, subcommand string, envs []string) error {
323 plugincmd, err := pluginmanager.PluginRunCommand(dockerCli, subcommand, cmd)

Callers 1

newDockerCommandFunction · 0.85

Calls 2

hasTagsFunction · 0.85
isSupportedFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…