MCPcopy Create free account
hub / github.com/containerd/nerdctl / MapBoolValueAsOpt

Function MapBoolValueAsOpt

pkg/maputil/maputil.go:33–46  ·  view source on GitHub ↗

MapBoolValueAsOpt will parse key as a command-line option. If only key is specified will be treated as true, otherwise, the value will be parsed and returned. This is useful when command line flags have options. Following examples illustrate this: --security-opt xxx returns true --security-opt xxx=t

(m map[string]string, key string)

Source from the content-addressed store, hash-verified

31// --security-opt xxx=false returns false
32// --security-opt xxx=invalid returns false and error
33func MapBoolValueAsOpt(m map[string]string, key string) (bool, error) {
34 if str, ok := m[key]; ok {
35 if str == "" {
36 return true, nil
37 }
38 b, err := strconv.ParseBool(str)
39 if err != nil {
40 return false, fmt.Errorf("invalid \"%s\" value: %q: %w", key, str, err)
41 }
42 return b, nil
43 }
44
45 return false, nil
46}

Callers 3

generateRootfsOptsFunction · 0.92
generateSecurityOptsFunction · 0.92
TestMapBoolValueAsOptFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestMapBoolValueAsOptFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…