@@ -59,6 +59,12 @@ def assert_hash(key, value, whitelist = nil)
5959 end
6060 end
6161
62+ def assert_uniq ( key , value , array_key )
63+ return unless value
64+ list = value . map { |c | c [ array_key ] } . compact . flatten
65+ assert list . uniq? , "#{ key } cannot have elements with similar #{ array_key } values"
66+ end
67+
6268 def assert_string_or_array ( key , value )
6369 return unless value
6470 assert [ Array , String ] . include? ( value . class ) ,
@@ -149,7 +155,7 @@ def assert_env_var(key, value)
149155 assert_boolean "#{ key } .required" , value [ 'required' ]
150156 end
151157
152- def assert_command ( key , value )
158+ def assert_command ( key , value )
153159 assert_hash key , value , Script ::Command . option_keys
154160
155161 refute value [ 'commands' ] && value [ 'args' ] , "#{ key } cannot have both commands and args"
@@ -177,6 +183,12 @@ def assert_command(key, value)
177183 assert_array "#{ key } .environment_variables" , value [ 'environment_variables' ] , of : :env_var
178184 assert_array "#{ key } .examples" , value [ 'examples' ] , of : :string
179185
186+ assert_uniq "#{ key } .commands" , value [ 'commands' ] , 'name'
187+ assert_uniq "#{ key } .commands" , value [ 'commands' ] , 'alias'
188+ assert_uniq "#{ key } .flags" , value [ 'flags' ] , 'long'
189+ assert_uniq "#{ key } .flags" , value [ 'flags' ] , 'short'
190+ assert_uniq "#{ key } .args" , value [ 'args' ] , 'name'
191+
180192 if value [ 'catch_all' ] and value [ 'args' ]
181193 repeatable_arg = value [ 'args' ] . select { |a | a [ 'repeatable' ] } . first &.dig 'name'
182194 refute repeatable_arg , "#{ key } .catch_all makes no sense with repeatable arg (#{ repeatable_arg } )"
0 commit comments