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

Function newConfigCreateCommand

cli/command/config/create.go:26–65  ·  view source on GitHub ↗
(dockerCLI command.Cli)

Source from the content-addressed store, hash-verified

24}
25
26func newConfigCreateCommand(dockerCLI command.Cli) *cobra.Command {
27 createOpts := createOptions{
28 labels: opts.NewListOpts(opts.ValidateLabel),
29 }
30
31 cmd := &cobra.Command{
32 Use: "create [OPTIONS] CONFIG file|-",
33 Short: "Create a config from a file or STDIN",
34 Args: cli.ExactArgs(2),
35 RunE: func(cmd *cobra.Command, args []string) error {
36 createOpts.name = args[0]
37 createOpts.file = args[1]
38 return runCreate(cmd.Context(), dockerCLI, createOpts)
39 },
40 ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
41 switch len(args) {
42 case 0:
43 // No completion for the first argument, which is the name for
44 // the new config, but if a non-empty name is given, we return
45 // it as completion to allow "tab"-ing to the next completion.
46 return []string{toComplete}, cobra.ShellCompDirectiveNoFileComp
47 case 1:
48 // Second argument is either "-" or a file to load.
49 //
50 // TODO(thaJeztah): provide completion for "-".
51 return nil, cobra.ShellCompDirectiveNoSpace | cobra.ShellCompDirectiveDefault
52 default:
53 // Command only accepts two arguments.
54 return nil, cobra.ShellCompDirectiveNoSpace | cobra.ShellCompDirectiveNoFileComp
55 }
56 },
57 DisableFlagsInUseLine: true,
58 }
59 flags := cmd.Flags()
60 flags.VarP(&createOpts.labels, "label", "l", "Config labels")
61 flags.StringVar(&createOpts.templateDriver, "template-driver", "", "Template driver")
62 _ = flags.SetAnnotation("template-driver", "version", []string{"1.37"})
63
64 return cmd
65}
66
67// runCreate creates a config with the given options.
68func runCreate(ctx context.Context, dockerCLI command.Cli, options createOptions) error {

Callers 5

TestConfigCreateErrorsFunction · 0.85
TestConfigCreateWithNameFunction · 0.85
newConfigCommandFunction · 0.85

Calls 1

runCreateFunction · 0.70

Tested by 4

TestConfigCreateErrorsFunction · 0.68
TestConfigCreateWithNameFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…