Skip to content

Commit 836b2ce

Browse files
committed
add validation tests for default arrays
1 parent 203c588 commit 836b2ce

File tree

6 files changed

+48
-0
lines changed

6 files changed

+48
-0
lines changed

lib/bashly/config_validator.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ def assert_arg(key, value)
110110
if value['default'].is_a? Array
111111
assert value['repeatable'], "#{key}.default array does not make sense without nub`repeatable`"
112112
end
113+
114+
if value['repeatable'] && value['default']
115+
assert value['default'].is_a?(Array), "#{key}.default must be an array when using nub`repeatable`"
116+
end
113117
end
114118

115119
def assert_flag(key, value)
@@ -159,6 +163,10 @@ def assert_flag(key, value)
159163
if value['default'].is_a? Array
160164
assert value['repeatable'], "#{key}.default array does not make sense without nub`repeatable`"
161165
end
166+
167+
if value['repeatable'] && value['default']
168+
assert value['default'].is_a?(Array), "#{key}.default must be an array when using nub`repeatable`"
169+
end
162170
end
163171

164172
def assert_env_var(key, value)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Bashly::ConfigurationError: root.args[0].default array does not make sense without nub`repeatable`>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Bashly::ConfigurationError: root.args[0].default must be an array when using nub`repeatable`>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Bashly::ConfigurationError: root.flags[0].default array does not make sense without nub`repeatable`>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Bashly::ConfigurationError: root.flags[0].default must be an array when using nub`repeatable`>

spec/fixtures/script/validations.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44
args:
55
- name: --user
66

7+
:arg_default_array_without_repeatable:
8+
name: invalid
9+
help: default cannot be an array without repeatable
10+
args:
11+
- name: path
12+
default:
13+
- spaced file
14+
- other-file
15+
16+
:arg_default_string_with_repeatable:
17+
name: invalid
18+
help: default cannot be a string with repeatable
19+
args:
20+
- name: path
21+
repeatable: true
22+
default: spaced file
23+
724
:arg_nested_name:
825
name: invalid
926
help: last nested arg does not have a name
@@ -257,6 +274,25 @@
257274
- long: --role
258275
default: admin
259276

277+
:flag_default_array_without_repeatable:
278+
name: invalid
279+
help: default cannot be an array without repeatable
280+
flags:
281+
- long: --path
282+
arg: location
283+
default:
284+
- spaced file
285+
- other-file
286+
287+
:flag_default_string_with_repeatable:
288+
name: invalid
289+
help: default cannot be a string with repeatable
290+
flags:
291+
- long: --path
292+
arg: location
293+
repeatable: true
294+
default: spaced file
295+
260296
:flag_allowed_without_arg:
261297
name: invalid
262298
help: flag must have an arg when using allowed

0 commit comments

Comments
 (0)