mirror of
https://github.com/docker/cli.git
synced 2025-08-29 00:47:54 +03:00
Ignore unknown arguments on the top-level command.
This allows passing argument to plugins, otherwise they are caught by the parse loop, since cobra does not know about each plugin at this stage (to avoid having to always scan for all plugins) this means that e.g. `docker plugin --foo` would accumulate `plugin` as an arg to the `docker` command, then choke on the unknown `--foo`. This allows unknown global args only, unknown arguments on subcommands (e.g. `docker ps --foo`) are still correctly caught. Add an e2e test covering this case. Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
@@ -33,6 +33,7 @@ func main() {
|
||||
},
|
||||
}
|
||||
|
||||
var who string
|
||||
cmd := &cobra.Command{
|
||||
Use: "helloworld",
|
||||
Short: "A basic Hello World plugin for tests",
|
||||
@@ -41,9 +42,11 @@ func main() {
|
||||
// hook.
|
||||
PersistentPreRunE: plugin.PersistentPreRunE,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Fprintln(dockerCli.Out(), "Hello World!")
|
||||
fmt.Fprintf(dockerCli.Out(), "Hello %s!\n", who)
|
||||
},
|
||||
}
|
||||
flags := cmd.Flags()
|
||||
flags.StringVar(&who, "who", "World", "Who are we addressing?")
|
||||
|
||||
cmd.AddCommand(goodbye, apiversion)
|
||||
return cmd
|
||||
|
Reference in New Issue
Block a user