Debian Codegraph @

control/keyval.go

raw symbols SCIP
1 package controlscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/
2
3 // KeyVal is a simple key-value struct. In cases where Val can be nil, an empty
4 // string represents that unless ValSetAndEmpty is true.
5 type KeyValscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal# struct {
6 // Key is the always-present key
7 Keyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal#Key. string
8
9 // Val is the value. If it's an empty string and nils are accepted/supported
10 // where this is used, it means nil unless ValSetAndEmpty is true.
11 Valscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal#Val. string
12
13 // ValSetAndEmpty is true when Val is an empty string, the associated
14 // command supports nils, and Val should NOT be treated as nil. False
15 // otherwise.
16 ValSetAndEmptyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal#ValSetAndEmpty. bool
17 }
18
19 // NewKeyVal creates a new key-value pair.
20 func NewKeyValscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/NewKeyVal().(key string, val string) *KeyValscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal# {
21 return &KeyValscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal#{Keyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal#Key.: key, Valscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal#Val.: val}
22 }
23
24 // KeyVals creates multiple new key-value pairs from the given strings. The
25 // provided set of strings must have a length that is a multiple of 2.
26 func KeyValsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVals().(keysAndVals ...string) []*KeyValscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal# {
27 if len(keysAndVals)%2 != 0 {
28 panic("Expected multiple of 2")
29 }
30 ret := make([]*KeyValscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal#, len(keysAndVals)/2)
31 for i := 0; i < len(ret); i++ {
32 ret[i] = NewKeyValscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/NewKeyVal().(keysAndVals[i*2], keysAndVals[i*2+1])
33 }
34 return ret
35 }
36
37 // ValSet returns true if Val is either non empty or ValSetAndEmpty is true.
38 func (k *KeyValscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal#) ValSetscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal#ValSet().() bool {
39 return len(k.Valscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal#Val.) > 0 || k.ValSetAndEmptyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal#ValSetAndEmpty.
40 }