MCPcopy
hub / github.com/kubernetes/test-infra / SetFieldDefault

Function SetFieldDefault

kubetest/util/util.go:190–196  ·  view source on GitHub ↗

SetFieldDefault sets the value of flag to val if flag is not present in fields. For example, SetFieldDefault(fields, "--foo", "bar") will append "--foo=bar" if fields is empty or does not include a "--foo" flag. It returns fields unchanged if "--foo" is present.

(fields []string, flag, val string)

Source from the content-addressed store, hash-verified

188// fields is empty or does not include a "--foo" flag.
189// It returns fields unchanged if "--foo" is present.
190func SetFieldDefault(fields []string, flag, val string) []string {
191 fields, cur, present := ExtractField(fields, flag)
192 if !present {
193 cur = val
194 }
195 return append(fields, flag+"="+cur)
196}
197
198// ExtractField input ("--a=this --b=that --c=other", "--b") returns [--a=this, --c=other"], "that", true
199//

Callers 4

argFieldsFunction · 0.92
kubemarkGinkgoTestFunction · 0.92
newGKEFunction · 0.92
TestSetFieldDefaultFunction · 0.85

Calls 1

ExtractFieldFunction · 0.85

Tested by 1

TestSetFieldDefaultFunction · 0.68