Skip to content

Commit bb524e6

Browse files
authored
Merge pull request #370 from DannyBen/add/allowed-pair-validation
Add validation alert when `allowed` is provided without either a `default` or `required`
2 parents 426120d + 6e84cba commit bb524e6

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

examples/completions/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ commands:
6060
- curl
6161
- wget
6262

63+
default: curl
64+
6365
examples:
6466
- cli download example.com
6567
- cli download example.com ./output -f

examples/completions/src/bashly.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ commands:
3838
- curl
3939
- wget
4040

41+
default: curl
42+
4143
examples:
4244
- cli download example.com
4345
- cli download example.com ./output -f

lib/bashly/config_validator.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ def assert_arg(key, value)
101101
refute value['name'].match(/^-/), "#{key}.name must not start with '-'"
102102

103103
refute value['required'] && value['default'], "#{key} cannot have both required and default"
104+
105+
if value['allowed']
106+
assert (value['required'] || value['default']),
107+
"#{key}.allowed does not make sense without either default or required"
108+
end
104109
end
105110

106111
def assert_flag(key, value)
@@ -135,6 +140,8 @@ def assert_flag(key, value)
135140

136141
if value['allowed']
137142
assert value['arg'], "#{key}.allowed does not make sense without arg"
143+
assert (value['required'] || value['default']),
144+
"#{key}.allowed does not make sense without either default or required"
138145
end
139146

140147
if value['completions']

0 commit comments

Comments
 (0)