MCPcopy
hub / github.com/nektos/act / parse

Function parse

pkg/container/docker_cli.go:349–748  ·  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

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

Callers 3

mergeContainerConfigsMethod · 0.70
parseRunFunction · 0.70
TestParseModesFunction · 0.70

Calls 10

makeFunction · 0.85
validateDeviceFunction · 0.85
parseDeviceFunction · 0.85
parseLoggingOptsFunction · 0.85
parseSecurityOptsFunction · 0.85
parseSystemPathsFunction · 0.85
parseStorageOptsFunction · 0.85
toNetipAddrSliceFunction · 0.85
parseNetworkOptsFunction · 0.85

Tested by 2

parseRunFunction · 0.56
TestParseModesFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…