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

Function parse

cli/command/container/opts.go:342–741  ·  view source on GitHub ↗

parse parses the args for the specified command and generates a Config, a HostConfig and returns them with the specified command. If the specified args are not valid, it will return an error. nolint:gocyclo

(flags *pflag.FlagSet, copts *containerOptions, serverOS string)

Source from the content-addressed store, hash-verified

340//
341//nolint:gocyclo
342func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*containerConfig, error) {
343 var (
344 attachStdin = copts.attach.Get("stdin")
345 attachStdout = copts.attach.Get("stdout")
346 attachStderr = copts.attach.Get("stderr")
347 )
348
349 // Validate the input mac address
350 if copts.macAddress != "" {
351 if _, err := net.ParseMAC(strings.TrimSpace(copts.macAddress)); err != nil {
352 return nil, fmt.Errorf("%s is not a valid mac address", copts.macAddress)
353 }
354 }
355 if copts.stdin {
356 attachStdin = true
357 }
358 // If -a is not set, attach to stdout and stderr
359 if copts.attach.Len() == 0 {
360 attachStdout = true
361 attachStderr = true
362 }
363
364 var err error
365
366 swappiness := copts.swappiness
367 if swappiness != -1 && (swappiness < 0 || swappiness > 100) {
368 return nil, fmt.Errorf("invalid value: %d. Valid memory swappiness range is 0-100", swappiness)
369 }
370
371 var binds []string
372 volumes := copts.volumes.GetMap()
373 // add any bind targets to the list of container volumes
374 for bind := range volumes {
375 parsed, err := volumespec.Parse(bind)
376 if err != nil {
377 return nil, err
378 }
379
380 if parsed.Source != "" {
381 toBind := bind
382
383 if parsed.Type == string(mount.TypeBind) {
384 if hostPart, targetPath, ok := strings.Cut(bind, ":"); ok {
385 if !filepath.IsAbs(hostPart) && strings.HasPrefix(hostPart, ".") {
386 if absHostPart, err := filepath.Abs(hostPart); err == nil {
387 hostPart = absHostPart
388 }
389 }
390 toBind = hostPart + ":" + targetPath
391 }
392 }
393
394 // after creating the bind mount we want to delete it from the copts.volumes values because
395 // we do not want bind mounts being committed to image configs
396 binds = append(binds, toBind)
397 // We should delete from the map (`volumes`) here, as deleting from copts.volumes will not work if
398 // there are duplicates entries.
399 delete(volumes, bind)

Callers 4

parseRunFunction · 0.85
TestParseModesFunction · 0.85
runRunFunction · 0.85
runCreateFunction · 0.85

Calls 15

validateDeviceFunction · 0.85
parseDeviceFunction · 0.85
parseLoggingOptsFunction · 0.85
parseSecurityOptsFunction · 0.85
parseSystemPathsFunction · 0.85
parseStorageOptsFunction · 0.85
parseNetworkOptsFunction · 0.85
GetMapMethod · 0.80
GetSliceMethod · 0.80
GetAllOrEmptyMethod · 0.80
NetworkModeMethod · 0.80

Tested by 2

parseRunFunction · 0.68
TestParseModesFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…