From 6863fe2d357ae8dfa4f7e92098c872e67da448aa Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 18 May 2022 15:21:31 +0200 Subject: [PATCH] add completion command to generate shell completion scripts Use the cobra lib to automatically generate shell completion scripts. We can use the completion command which is automatically added, since it is not importent for most users we hide it. To test the new script on bash you can use `source <(bin/skopeo completion bash)` Signed-off-by: Paul Holzinger --- cmd/skopeo/main.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cmd/skopeo/main.go b/cmd/skopeo/main.go index a6714ce2..3f8a9621 100644 --- a/cmd/skopeo/main.go +++ b/cmd/skopeo/main.go @@ -63,11 +63,8 @@ func createApp() (*cobra.Command, *globalOptions) { }, SilenceUsage: true, SilenceErrors: true, - // Currently, skopeo uses manually written completions. Cobra allows - // for auto-generating completions for various shells. Podman is - // already making us of that. If Skopeo decides to follow, please - // remove the line below (and hide the `completion` command). - CompletionOptions: cobra.CompletionOptions{DisableDefaultCmd: true}, + // Hide the completion command which is provided by cobra + CompletionOptions: cobra.CompletionOptions{HiddenDefaultCmd: true}, // This is documented to parse "local" (non-PersistentFlags) flags of parent commands before // running subcommands and handling their options. We don't really run into such cases, // because all of our flags on rootCommand are in PersistentFlags, except for the deprecated --tls-verify;