@@ -96,17 +96,36 @@ func parseStyle(styleOpt string) (table.Style, error) {
96
96
97
97
// parseCommaSeparatedValues parses comma separated string into a map.
98
98
func parseCommaSeparatedValues (values string ) map [string ]struct {} {
99
- items := make (map [string ]struct {})
100
- for _ , value := range strings .Split (values , "," ) {
101
- value = strings .TrimSpace (value )
102
- if len (value ) == 0 {
99
+ m := make (map [string ]struct {})
100
+ for _ , v := range strings .Split (values , "," ) {
101
+ v = strings .TrimSpace (v )
102
+ if len (v ) == 0 {
103
103
continue
104
104
}
105
- value = strings .ToLower (value )
106
105
107
- items [value ] = struct {}{}
106
+ v = strings .ToLower (v )
107
+ m [v ] = struct {}{}
108
108
}
109
- return items
109
+ return m
110
+ }
111
+
112
+ // validateGroups validates the parsed group maps.
113
+ func validateGroups (m map [string ]struct {}) error {
114
+ for k := range m {
115
+ found := false
116
+ for _ , g := range groups {
117
+ if g == k {
118
+ found = true
119
+ break
120
+ }
121
+ }
122
+
123
+ if ! found {
124
+ return fmt .Errorf ("unknown device group: %s" , k )
125
+ }
126
+ }
127
+
128
+ return nil
110
129
}
111
130
112
131
func main () {
@@ -189,6 +208,16 @@ func main() {
189
208
HiddenFilesystems : parseCommaSeparatedValues (* hideFs ),
190
209
OnlyFilesystems : parseCommaSeparatedValues (* onlyFs ),
191
210
}
211
+ err = validateGroups (filters .HiddenDevices )
212
+ if err != nil {
213
+ fmt .Println (err )
214
+ os .Exit (1 )
215
+ }
216
+ err = validateGroups (filters .OnlyDevices )
217
+ if err != nil {
218
+ fmt .Println (err )
219
+ os .Exit (1 )
220
+ }
192
221
193
222
// validate arguments
194
223
if len (flag .Args ()) > 0 {
0 commit comments