Skip to content

Commit 220150d

Browse files
authored
Merge pull request #455 from DannyBen/fix/repeatable-arg-validation
Disallow multiple repeatable args, and a repeatable arg that is not the last one
2 parents 12b8cdd + f4ac880 commit 220150d

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

lib/bashly/config_validator.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,16 @@ def assert_command(key, value)
207207
refute repeatable_arg, "#{key}.catch_all makes no sense with repeatable arg (#{repeatable_arg})"
208208
end
209209

210+
if value['args']
211+
repeatable_args = value['args'].count { |a| a['repeatable'] }
212+
assert repeatable_args < 2, "#{key}.args cannot have more than one repeatable args"
213+
214+
if repeatable_args == 1
215+
assert value['args'].last['repeatable'],
216+
"#{key}.args cannot contain a repeatable arg unless it is the last one"
217+
end
218+
end
219+
210220
if value['expose']
211221
assert value['commands'], "#{key}.expose makes no sense without nub`commands`"
212222
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Bashly::ConfigurationError: root.args cannot have more than one repeatable args>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Bashly::ConfigurationError: root.args cannot contain a repeatable arg unless it is the last one>

spec/fixtures/script/validations.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,29 @@
1919
- name: ok
2020
- help: there is no name
2121

22+
:arg_repeatable_more_than_one:
23+
name: invalid
24+
help: can only have one repeatable arg
25+
args:
26+
- name: source
27+
required: true
28+
repeatable: true
29+
help: URL to download from
30+
- name: target
31+
repeatable: true
32+
help: Target filename
33+
34+
:arg_repeatable_not_last:
35+
name: invalid
36+
help: can the last arg can be repeatable
37+
args:
38+
- name: source
39+
required: true
40+
repeatable: true
41+
help: URL to download from
42+
- name: target
43+
help: Target filename
44+
2245
:command_catch_all_type:
2346
name: invalid
2447
help: catch_all must be boolean, string, or hash

0 commit comments

Comments
 (0)