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)
| 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. |
| 295 | func 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 | |
| 322 | func tryPluginRun(ctx context.Context, dockerCli command.Cli, cmd *cobra.Command, subcommand string, envs []string) error { |
| 323 | plugincmd, err := pluginmanager.PluginRunCommand(dockerCli, subcommand, cmd) |
no test coverage detected
searching dependent graphs…