Skip to content

Commit dfdc71c

Browse files
authored
Merge pull request #209 from DannyBen/add/catch-all-validation
Disallow catch_all together with repeatable arg
2 parents 29af3ab + 6a8c8c8 commit dfdc71c

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

lib/bashly/config_validator.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def assert_command(key, value)
138138

139139
refute value['commands'] && value['args'], "#{key} cannot have both commands and args"
140140
refute value['commands'] && value['flags'], "#{key} cannot have both commands and flags"
141-
141+
142142
assert_string "#{key}.name", value['name']
143143
assert_optional_string "#{key}.short", value['short']
144144
assert_optional_string "#{key}.help", value['help']
@@ -161,6 +161,11 @@ def assert_command(key, value)
161161
assert_array "#{key}.environment_variables", value['environment_variables'], of: :env_var
162162
assert_array "#{key}.examples", value['examples'], of: :string
163163

164+
if value['catch_all'] and value['args']
165+
repeatable_arg = value['args'].select { |a| a['repeatable'] }.first&.dig 'name'
166+
refute repeatable_arg, "#{key}.catch_all makes no sense with repeatable arg (#{repeatable_arg})"
167+
end
168+
164169
if key == "root"
165170
refute value['short'], "#{key}.short makes no sense"
166171
refute value['group'], "#{key}.group makes no sense"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Bashly::ConfigurationError: root.catch_all makes no sense with repeatable arg (path)>

spec/fixtures/script/validations.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,12 @@
200200
- long: --user
201201
disallowed: true
202202

203+
:catch_all_and_repeatable_arg:
204+
name: invalid
205+
help: catch_all and repeatable arg make no sense together
206+
catch_all: true
207+
args:
208+
- name: path
209+
help: Path to one or more files
210+
repeatable: true
211+
required: true

0 commit comments

Comments
 (0)