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

Function preparePluginStubCommand

cli-plugins/manager/cobra_test.go:55–85  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

53}
54
55func preparePluginStubCommand(t *testing.T) (*cobra.Command, error) {
56 t.Helper()
57 pluginCommandStubsOnce = sync.Once{}
58
59 tmpDir := t.TempDir()
60 const cliPlugin = `#!/bin/sh
61printf '%s' '{"SchemaVersion":"0.1.0"}'
62`
63 if err := os.WriteFile(filepath.Join(tmpDir, "docker-testplugin"), []byte(cliPlugin), 0o777); err != nil {
64 return nil, err
65 }
66
67 cli := test.NewFakeCli(nil)
68 cli.ConfigFile().CLIPluginsExtraDirs = []string{tmpDir}
69
70 root := &cobra.Command{Use: "docker"}
71 root.PersistentFlags().Bool("debug", false, "")
72
73 if err := AddPluginCommandStubs(cli, root); err != nil {
74 return nil, err
75 }
76
77 cmd, _, err := root.Find([]string{"testplugin"})
78 if err != nil {
79 return nil, err
80 }
81 if cmd == nil {
82 return nil, os.ErrNotExist
83 }
84 return cmd, nil
85}

Calls 2

ConfigFileMethod · 0.95
AddPluginCommandStubsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…