blob: dba73c1e8c13eb0785258725920afb8fa387751e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
package boolean
import (
"strings"
)
// IsSingleFlagPresent checks presence of selected flag and whether it was used once.
func IsSingleFlagPresent(flag string, params []string) bool {
found := filterFlags(params, flag)
if len(found) != 1 {
return false
}
return true
}
// IsFlagAbsent checks absence of selected flag in parameters.
func IsFlagAbsent(flag string, params []string) bool {
found := filterFlags(params, flag)
if len(found) != 0 {
return false
}
return true
}
// filterFlags returns all occurrences of selected flag.
func filterFlags(strs []string, flag string) []string {
var filtered []string
for _, str := range strs {
if strings.HasPrefix(str, flag) {
filtered = append(filtered, str)
}
}
return filtered
}
|