-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic framework for writing and running CLI plugins #1564
Commits on Jan 29, 2019
-
Fold
dockerPreRun
intoDockerCli.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>
Ian Campbell committedJan 29, 2019 Configuration menu - View commit details
-
Copy full SHA for 158a766 - Browse repository at this point
Copy the full SHA 158a766View commit details -
Move
disableFlagsInUseLine
frommain
into ourcli
library... and expose. I would like to use this from another site. This implies also moving (and exposing) the `visitAll` helper. Unit test them while I'm here. Signed-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 29, 2019 Configuration menu - View commit details
-
Copy full SHA for ccef159 - Browse repository at this point
Copy the full SHA ccef159View commit details -
Refactor common bits of
SetupRootCommand
I'm shortly going to add a second user to setup plugins, which will want to reuse the common bits. Signed-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 29, 2019 Configuration menu - View commit details
-
Copy full SHA for 38645ca - Browse repository at this point
Copy the full SHA 38645caView commit details -
Push setup of opts and default flagset into SetupRootCommand
I'm shortly going to add a second user (plugins) which want to share some behaviour. Signed-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 29, 2019 Configuration menu - View commit details
-
Copy full SHA for c516811 - Browse repository at this point
Copy the full SHA c516811View commit details -
Move versioning variables to a separate package.
This helps to avoid circular includes, by separating the pure data out from the actual functionality in the cli subpackage, allowing other code which is imported to access the data. Signed-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 29, 2019 Configuration menu - View commit details
-
Copy full SHA for 20c1983 - Browse repository at this point
Copy the full SHA 20c1983View commit details -
cli/config: Add a helper to resolve a file within the config dir
Signed-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 29, 2019 Configuration menu - View commit details
-
Copy full SHA for eab40a5 - Browse repository at this point
Copy the full SHA eab40a5View commit details -
Unit test for WithContentTrustFromEnv
I authored this for `contentTrustEnabled` prior to 7f207f3, so this now tests the funcation argument version. Signed-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 29, 2019 Configuration menu - View commit details
-
Copy full SHA for 8cf946d - Browse repository at this point
Copy the full SHA 8cf946dView commit details -
Add basic framework for writing a CLI plugin
That is, the helper to be used from the plugin's `main`. Also add a `helloworld` plugin example and build integration. Signed-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 29, 2019 Configuration menu - View commit details
-
Copy full SHA for e962404 - Browse repository at this point
Copy the full SHA e962404View commit details
Commits on Jan 30, 2019
-
Add support for running a CLI plugin
Also includes the scaffolding for finding a validating plugin candidates. Argument validation is moved to RunE to support this, so `noArgs` is removed. Signed-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 30, 2019 Configuration menu - View commit details
-
Copy full SHA for f1f31ab - Browse repository at this point
Copy the full SHA f1f31abView commit details -
Add some simple e2e tests for executing CLI plugins
To help with this add a bad plugin which produces invalid metadata and arrange for it to be built in the e2e container. Signed-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 30, 2019 Configuration menu - View commit details
-
Copy full SHA for 5db3367 - Browse repository at this point
Copy the full SHA 5db3367View commit details -
Integrate CLI plugins into
docker help
output.To do this we add a stub `cobra.Command` for each installed plugin (only when invoking `help`, not for normal running). This requires a function to list all available plugins so that is added here. Signed-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 30, 2019 Configuration menu - View commit details
-
Copy full SHA for f912b55 - Browse repository at this point
Copy the full SHA f912b55View commit details -
Add stubs when calling help due to no arguments
e.g. the `docker` case which should act as `docker help`. Signed-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 30, 2019 Configuration menu - View commit details
-
Copy full SHA for c43da09 - Browse repository at this point
Copy the full SHA c43da09View commit details -
Integrate CLI plugins with
docker help «foo»
Signed-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 30, 2019 Configuration menu - View commit details
-
Copy full SHA for 20a2847 - Browse repository at this point
Copy the full SHA 20a2847View commit details -
Integrate CLI plugins with
docker «plugin» --help
.To achieve this we hook in at the beginning of our custom `HelpFunc` and detect the plugin case by adding stub commands. Signed-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 30, 2019 Configuration menu - View commit details
-
Copy full SHA for 53f0181 - Browse repository at this point
Copy the full SHA 53f0181View commit details -
Allow plugins to make use of the cobra
PersistentPreRun
hooks.Previously a plugin which used these hooks would overwrite the top-level plugin command's use of this hook, resulting in the dockerCli object not being fully initialised. Provide a function which plugins can use to chain to the required behaviour. This required some fairly ugly arrangements to preserve state (which was previously in-scope in `newPluginCOmmand`) to be used by the new function. Signed-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 30, 2019 Configuration menu - View commit details
-
Copy full SHA for e5e578a - Browse repository at this point
Copy the full SHA e5e578aView commit details -
Output broken CLI plugins in
help
output.Signed-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 30, 2019 Configuration menu - View commit details
-
Copy full SHA for 0ab8ec0 - Browse repository at this point
Copy the full SHA 0ab8ec0View commit details -
Integrate CLI plugins into
docker info
Fairly straight forward. It became necessary to wrap `Plugin.Err` with a type which implements `encoding.MarshalText` in order to have that field rendered properly in the `docker info -f '{{json}}'` output. Since I changed the type somewhat I also added a unit test for `formatInfo`. Signed-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 30, 2019 Configuration menu - View commit details
-
Copy full SHA for 1c576e9 - Browse repository at this point
Copy the full SHA 1c576e9View commit details -
Documentation on writing a plugin
Signed-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 30, 2019 Configuration menu - View commit details
-
Copy full SHA for 609dcb9 - Browse repository at this point
Copy the full SHA 609dcb9View commit details -
Refactor code which deals with Windows'
.exe
suffixSigned-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 30, 2019 Configuration menu - View commit details
-
Copy full SHA for 63f3ad1 - Browse repository at this point
Copy the full SHA 63f3ad1View commit details -
Check for
.exe
case insensitivelyOn Windows `foo.exe`, `foo.eXe` and `foo.EXE` are equally executable. Signed-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 30, 2019 Configuration menu - View commit details
-
Copy full SHA for 1337895 - Browse repository at this point
Copy the full SHA 1337895View commit details -
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>
Ian Campbell committedJan 30, 2019 Configuration menu - View commit details
-
Copy full SHA for 935d47b - Browse repository at this point
Copy the full SHA 935d47bView commit details -
Ensure plugins default search path obeys
--config
A static global initialiser happens before the arguments are parsed, so we need to calculate the path later. Signed-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 30, 2019 Configuration menu - View commit details
-
Copy full SHA for 0a89eb5 - Browse repository at this point
Copy the full SHA 0a89eb5View commit details -
Ensure that plugins are only listed once in help outputs.
They were listed twice in `docker --help` (but not `docker help`), since the stubs were added in both `tryRunPluginHelp` and the `setHelpFunc` closure. Calling `AddPluginStubCommands` earlier in `setHelpFunc` before the call to `tryRunPluginHelp` is sufficient. Also it is no longer necessary to add just valid plugins (`tryRunPluginHelp` handles invalid plugins correctly) so remove that logic (which was in any case broken for e.g. `docker --help`). Update the e2e test to check for duplicate entries and also to test `docker --help` which was previously missed. Signed-off-by: Ian Campbell <ijc@docker.com>
Ian Campbell committedJan 30, 2019 Configuration menu - View commit details
-
Copy full SHA for baabf6e - Browse repository at this point
Copy the full SHA baabf6eView commit details