MCPcopy Index your code
hub / github.com/docker/cli / newPluginCommand

Function newPluginCommand

cli-plugins/plugin/plugin.go:150–193  ·  view source on GitHub ↗
(dockerCli *command.DockerCli, plugin *cobra.Command, meta metadata.Metadata)

Source from the content-addressed store, hash-verified

148}
149
150func 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.
196func visitAll(root *cobra.Command, fns ...func(*cobra.Command)) {

Callers 1

RunPluginFunction · 0.70

Calls 9

newMetadataSubcommandFunction · 0.85
visitAllFunction · 0.70
SetInMethod · 0.65
InMethod · 0.65
OutMethod · 0.65
ErrMethod · 0.65
NameMethod · 0.45
SetOutMethod · 0.45
SetErrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…