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)
| 31 | // --security-opt xxx=false returns false |
| 32 | // --security-opt xxx=invalid returns false and error |
| 33 | func 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 | } |
no outgoing calls
searching dependent graphs…