Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/bashly/config_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ def assert_command(key, value)
refute repeatable_arg, "#{key}.catch_all makes no sense with repeatable arg (#{repeatable_arg})"
end

if value['args']
repeatable_args = value['args'].count { |a| a['repeatable'] }
assert repeatable_args < 2, "#{key}.args cannot have more than one repeatable args"

if repeatable_args == 1
assert value['args'].last['repeatable'],
"#{key}.args cannot contain a repeatable arg unless it is the last one"
end
end

if value['expose']
assert value['commands'], "#{key}.expose makes no sense without nub`commands`"
end
Expand Down
1 change: 1 addition & 0 deletions spec/approvals/validations/arg_repeatable_more_than_one
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: root.args cannot have more than one repeatable args>
1 change: 1 addition & 0 deletions spec/approvals/validations/arg_repeatable_not_last
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: root.args cannot contain a repeatable arg unless it is the last one>
23 changes: 23 additions & 0 deletions spec/fixtures/script/validations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@
- name: ok
- help: there is no name

:arg_repeatable_more_than_one:
name: invalid
help: can only have one repeatable arg
args:
- name: source
required: true
repeatable: true
help: URL to download from
- name: target
repeatable: true
help: Target filename

:arg_repeatable_not_last:
name: invalid
help: can the last arg can be repeatable
args:
- name: source
required: true
repeatable: true
help: URL to download from
- name: target
help: Target filename

:command_catch_all_type:
name: invalid
help: catch_all must be boolean, string, or hash
Expand Down