(dockerCli *command.DockerCli, plugin *cobra.Command, meta metadata.Metadata)
| 148 | } |
| 149 | |
| 150 | func newPluginCommand(dockerCli *command.DockerCli, plugin *cobra.Command, meta metadata.Metadata) *cli.TopLevelCommand { |
| 151 | name := plugin.Name() |
| 152 | fullname := metadata.NamePrefix + name |
| 153 | |
| 154 | cmd := &cobra.Command{ |
| 155 | Use: fmt.Sprintf("docker [OPTIONS] %s [ARG...]", name), |
| 156 | Short: fullname + " is a Docker CLI plugin", |
| 157 | SilenceUsage: true, |
| 158 | SilenceErrors: true, |
| 159 | PersistentPreRunE: func(cmd *cobra.Command, args []string) error { |
| 160 | // We can't use this as the hook directly since it is initialised later (in runPlugin) |
| 161 | return PersistentPreRunE(cmd, args) |
| 162 | }, |
| 163 | TraverseChildren: true, |
| 164 | DisableFlagsInUseLine: true, |
| 165 | CompletionOptions: cobra.CompletionOptions{ |
| 166 | DisableDefaultCmd: false, |
| 167 | HiddenDefaultCmd: true, |
| 168 | DisableDescriptions: os.Getenv("DOCKER_CLI_DISABLE_COMPLETION_DESCRIPTION") != "", |
| 169 | }, |
| 170 | } |
| 171 | |
| 172 | // Disable file-completion by default. Most commands and flags should not |
| 173 | // complete with filenames. |
| 174 | cmd.CompletionOptions.SetDefaultShellCompDirective(cobra.ShellCompDirectiveNoFileComp) |
| 175 | |
| 176 | opts, _ := cli.SetupPluginRootCommand(cmd) |
| 177 | |
| 178 | cmd.SetIn(dockerCli.In()) |
| 179 | cmd.SetOut(dockerCli.Out()) |
| 180 | cmd.SetErr(dockerCli.Err()) |
| 181 | |
| 182 | cmd.AddCommand( |
| 183 | plugin, |
| 184 | newMetadataSubcommand(plugin, meta), |
| 185 | ) |
| 186 | |
| 187 | visitAll(cmd, |
| 188 | // prevent adding "[flags]" to the end of the usage line. |
| 189 | func(c *cobra.Command) { c.DisableFlagsInUseLine = true }, |
| 190 | ) |
| 191 | |
| 192 | return cli.NewTopLevelCommand(cmd, dockerCli, opts, cmd.Flags()) |
| 193 | } |
| 194 | |
| 195 | // visitAll traverses all commands from the root. |
| 196 | func visitAll(root *cobra.Command, fns ...func(*cobra.Command)) { |
no test coverage detected
searching dependent graphs…