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

Function newCreateCommand

cli/command/volume/create.go:42–108  ·  view source on GitHub ↗
(dockerCLI command.Cli)

Source from the content-addressed store, hash-verified

40}
41
42func newCreateCommand(dockerCLI command.Cli) *cobra.Command {
43 options := createOptions{
44 driverOpts: *opts.NewMapOpts(nil, nil),
45 labels: opts.NewListOpts(opts.ValidateLabel),
46 secrets: *opts.NewMapOpts(nil, nil),
47 requisiteTopology: opts.NewListOpts(nil),
48 preferredTopology: opts.NewListOpts(nil),
49 }
50
51 cmd := &cobra.Command{
52 Use: "create [OPTIONS] [VOLUME]",
53 Short: "Create a volume",
54 Args: cli.RequiresMaxArgs(1),
55 RunE: func(cmd *cobra.Command, args []string) error {
56 if len(args) == 1 {
57 if options.name != "" {
58 return errors.New("conflicting options: cannot specify a volume-name through both --name and as a positional arg")
59 }
60 options.name = args[0]
61 }
62 options.cluster = hasClusterVolumeOptionSet(cmd.Flags())
63 return runCreate(cmd.Context(), dockerCLI, options)
64 },
65 ValidArgsFunction: cobra.NoFileCompletions,
66 DisableFlagsInUseLine: true,
67 }
68 flags := cmd.Flags()
69 flags.StringVarP(&options.driver, "driver", "d", "local", "Specify volume driver name")
70 flags.StringVar(&options.name, "name", "", "Specify volume name")
71 flags.Lookup("name").Hidden = true
72 flags.VarP(&options.driverOpts, "opt", "o", "Set driver specific options")
73 flags.Var(&options.labels, "label", "Set metadata for a volume")
74
75 // flags for cluster volumes only
76 flags.StringVar(&options.group, "group", "", "Cluster Volume group (cluster volumes)")
77 flags.SetAnnotation("group", "version", []string{"1.42"})
78 flags.SetAnnotation("group", "swarm", []string{"manager"})
79 flags.StringVar(&options.scope, "scope", "single", `Cluster Volume access scope ("single", "multi")`)
80 flags.SetAnnotation("scope", "version", []string{"1.42"})
81 flags.SetAnnotation("scope", "swarm", []string{"manager"})
82 flags.StringVar(&options.sharing, "sharing", "none", `Cluster Volume access sharing ("none", "readonly", "onewriter", "all")`)
83 flags.SetAnnotation("sharing", "version", []string{"1.42"})
84 flags.SetAnnotation("sharing", "swarm", []string{"manager"})
85 flags.StringVar(&options.availability, "availability", "active", `Cluster Volume availability ("active", "pause", "drain")`)
86 flags.SetAnnotation("availability", "version", []string{"1.42"})
87 flags.SetAnnotation("availability", "swarm", []string{"manager"})
88 flags.StringVar(&options.accessType, "type", "block", `Cluster Volume access type ("mount", "block")`)
89 flags.SetAnnotation("type", "version", []string{"1.42"})
90 flags.SetAnnotation("type", "swarm", []string{"manager"})
91 flags.Var(&options.secrets, "secret", "Cluster Volume secrets")
92 flags.SetAnnotation("secret", "version", []string{"1.42"})
93 flags.SetAnnotation("secret", "swarm", []string{"manager"})
94 flags.Var(&options.limitBytes, "limit-bytes", "Minimum size of the Cluster Volume in bytes")
95 flags.SetAnnotation("limit-bytes", "version", []string{"1.42"})
96 flags.SetAnnotation("limit-bytes", "swarm", []string{"manager"})
97 flags.Var(&options.requiredBytes, "required-bytes", "Maximum size of the Cluster Volume in bytes")
98 flags.SetAnnotation("required-bytes", "version", []string{"1.42"})
99 flags.SetAnnotation("required-bytes", "swarm", []string{"manager"})

Callers 6

TestVolumeCreateErrorsFunction · 0.70
TestVolumeCreateWithNameFunction · 0.70
TestVolumeCreateClusterFunction · 0.70
newVolumeCommandFunction · 0.70

Calls 2

runCreateFunction · 0.70

Tested by 5

TestVolumeCreateErrorsFunction · 0.56
TestVolumeCreateWithNameFunction · 0.56
TestVolumeCreateClusterFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…