Skip to content

Commit 7559b03

Browse files
committed
update config validator to assert arg.unique
1 parent 4486788 commit 7559b03

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

lib/bashly/config_validator.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,17 @@ def assert_arg(key, value)
9595
assert_optional_string "#{key}.validate", value['validate']
9696
assert_boolean "#{key}.required", value['required']
9797
assert_boolean "#{key}.repeatable", value['repeatable']
98+
assert_boolean "#{key}.unique", value['unique']
9899

99100
assert_array "#{key}.allowed", value['allowed'], of: :string
100101

101102
refute value['name'].match(/^-/), "#{key}.name must not start with '-'"
102103

103104
refute value['required'] && value['default'], "#{key} cannot have both nub`required` and nub`default`"
105+
106+
if value['unique']
107+
assert value['repeatable'], "#{key}.unique does not make sense without nub`repeatable`"
108+
end
104109
end
105110

106111
def assert_flag(key, value)
@@ -143,8 +148,7 @@ def assert_flag(key, value)
143148
end
144149

145150
if value['unique']
146-
condition = value['arg'] && value['repeatable']
147-
assert condition, "#{key}.unique does not make sense without nub`arg` and nub`repeatable`"
151+
assert value['arg'] && value['repeatable'], "#{key}.unique does not make sense without nub`arg` and nub`repeatable`"
148152
end
149153
end
150154

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Bashly::ConfigurationError: root.args[0].unique does not make sense without nub`repeatable`>

spec/fixtures/script/validations.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242
- name: target
4343
help: Target filename
4444

45+
:arg_unique_without_repeatable:
46+
name: invalid
47+
help: arg must be repeatable when using unique
48+
args:
49+
- name: target
50+
help: Target filename
51+
unique: true
52+
4553
:command_catch_all_type:
4654
name: invalid
4755
help: catch_all must be boolean, string, or hash

0 commit comments

Comments
 (0)