Skip to content

Commit 87bb9d2

Browse files
committed
add validations for command.filters
1 parent 1c47799 commit 87bb9d2

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

lib/bashly/config_validator.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ def assert_extensible(key, value)
7272
"#{key} must be a boolean or a string"
7373
end
7474

75+
def assert_filters(key, value)
76+
return unless value
77+
assert [Array, String].include?(value.class),
78+
"#{key} must be an array or a string"
79+
80+
assert_array key, value, of: :string if value.is_a? Array
81+
end
82+
7583
def assert_arg(key, value)
7684
assert_hash key, value
7785
assert_string "#{key}.name", value['name']
@@ -129,6 +137,7 @@ def assert_command(key, value)
129137
assert_version "#{key}.version", value['version']
130138
assert_catch_all "#{key}.catch_all", value['catch_all']
131139
assert_extensible "#{key}.extensible", value['extensible']
140+
assert_filters "#{key}.filters", value['filters']
132141

133142
assert_array "#{key}.args", value['args'], of: :arg
134143
assert_array "#{key}.flags", value['flags'] , of: :flag
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Bashly::ConfigurationError: root.filters must be an array or a string>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Bashly::ConfigurationError: root.filters must be an array or a string>

spec/fixtures/script/validations.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,15 @@
6161
args:
6262
- name: --user
6363

64+
:invalid_filters_type:
65+
name: invalid
66+
help: invalid since command.filters should be an array or string
67+
filters: 1
68+
69+
:invalid_filters_array:
70+
name: invalid
71+
help: invalid since command.filters in array form must have strings
72+
filters:
73+
one: two
74+
three: four
75+

0 commit comments

Comments
 (0)