@@ -42,8 +42,13 @@ def assert_array(key, value, of: nil)
4242 end
4343 end
4444
45- def assert_hash ( key , value )
45+ def assert_hash ( key , value , whitelist = nil )
4646 assert value . is_a? ( Hash ) , "#{ key } must be a hash"
47+
48+ if whitelist
49+ invalid_keys = value . keys . map ( &:to_sym ) - whitelist
50+ assert invalid_keys . empty? , "#{ key } contains invalid options: #{ invalid_keys . join ( ', ' ) } "
51+ end
4752 end
4853
4954 def assert_version ( key , value )
@@ -61,6 +66,7 @@ def assert_catch_all(key, value)
6166 end
6267
6368 def assert_catch_all_hash ( key , value )
69+ assert_hash key , value , Script ::CatchAll . option_keys
6470 assert_string "#{ key } .label" , value [ 'label' ]
6571 assert_optional_string "#{ key } .help" , value [ 'help' ]
6672 assert_boolean "#{ key } .required" , value [ 'required' ]
@@ -73,7 +79,7 @@ def assert_extensible(key, value)
7379 end
7480
7581 def assert_arg ( key , value )
76- assert_hash key , value
82+ assert_hash key , value , Script :: Argument . option_keys
7783 assert_string "#{ key } .name" , value [ 'name' ]
7884 assert_optional_string "#{ key } .help" , value [ 'help' ]
7985 assert_optional_string "#{ key } .default" , value [ 'default' ]
@@ -89,7 +95,7 @@ def assert_arg(key, value)
8995 end
9096
9197 def assert_flag ( key , value )
92- assert_hash key , value
98+ assert_hash key , value , Script :: Flag . option_keys
9399 assert value [ 'short' ] || value [ 'long' ] , "#{ key } must have at least one of long or short name"
94100
95101 assert_optional_string "#{ key } .long" , value [ 'long' ]
@@ -120,15 +126,15 @@ def assert_flag(key, value)
120126 end
121127
122128 def assert_env_var ( key , value )
123- assert_hash key , value
129+ assert_hash key , value , Script :: EnvironmentVariable . option_keys
124130 assert_string "#{ key } .name" , value [ 'name' ]
125131 assert_optional_string "#{ key } .help" , value [ 'help' ]
126132 assert_optional_string "#{ key } .default" , value [ 'default' ]
127133 assert_boolean "#{ key } .required" , value [ 'required' ]
128134 end
129135
130136 def assert_command ( key , value )
131- assert_hash key , value
137+ assert_hash key , value , Script :: Command . option_keys
132138
133139 refute value [ 'commands' ] && value [ 'args' ] , "#{ key } cannot have both commands and args"
134140 refute value [ 'commands' ] && value [ 'flags' ] , "#{ key } cannot have both commands and flags"
@@ -140,6 +146,7 @@ def assert_command(key, value)
140146 assert_optional_string "#{ key } .group" , value [ 'group' ]
141147 assert_optional_string "#{ key } .filename" , value [ 'filename' ]
142148
149+ assert_boolean "#{ key } .private" , value [ 'private' ]
143150 assert_boolean "#{ key } .default" , value [ 'default' ]
144151 assert_version "#{ key } .version" , value [ 'version' ]
145152 assert_catch_all "#{ key } .catch_all" , value [ 'catch_all' ]
0 commit comments