Skip to content

Commit f075665

Browse files
authored
Merge pull request #371 from DannyBen/change/validation-message-highlights
Update validation errors to highlight words that are YAML options
2 parents bb524e6 + 176fb1e commit f075665

9 files changed

+20
-20
lines changed

lib/bashly/config_validator.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,19 @@ def assert_arg(key, value)
100100

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

103-
refute value['required'] && value['default'], "#{key} cannot have both required and default"
103+
refute value['required'] && value['default'], "#{key} cannot have both nub`required` and nub`default`"
104104

105105
if value['allowed']
106106
assert (value['required'] || value['default']),
107-
"#{key}.allowed does not make sense without either default or required"
107+
"#{key}.allowed does not make sense without either nub`default` or nub`required`"
108108
end
109109
end
110110

111111
def assert_flag(key, value)
112112
assert_hash key, value, keys: Script::Flag.option_keys
113-
assert value['short'] || value['long'], "#{key} must have at least one of long or short name"
113+
assert value['short'] || value['long'], "#{key} must have at least one of nub`long` or nub`short`"
114114

115-
refute value['allowed'] && value['completions'], "#{key} cannot have both allowed and completions"
115+
refute value['allowed'] && value['completions'], "#{key} cannot have both nub`allowed` and nub`completions`"
116116

117117
assert_optional_string "#{key}.long", value['long']
118118
assert_optional_string "#{key}.short", value['short']
@@ -132,20 +132,20 @@ def assert_flag(key, value)
132132
assert value['short'].match(/^-[a-zA-Z0-9]$/), "#{key}.short must be in the form of '-n'" if value['short']
133133
refute value['arg'].match(/^-/), "#{key}.arg must not start with '-'" if value['arg']
134134

135-
refute value['required'] && value['default'], "#{key} cannot have both required and default"
135+
refute value['required'] && value['default'], "#{key} cannot have both nub`required` and nub`default`"
136136

137137
if value['default']
138-
assert value['arg'], "#{key}.default does not make sense without arg"
138+
assert value['arg'], "#{key}.default does not make sense without nub`arg`"
139139
end
140140

141141
if value['allowed']
142-
assert value['arg'], "#{key}.allowed does not make sense without arg"
142+
assert value['arg'], "#{key}.allowed does not make sense without nub`arg`"
143143
assert (value['required'] || value['default']),
144-
"#{key}.allowed does not make sense without either default or required"
144+
"#{key}.allowed does not make sense without either nub`default` or nub`required`"
145145
end
146146

147147
if value['completions']
148-
assert value['arg'], "#{key}.completions does not make sense without arg"
148+
assert value['arg'], "#{key}.completions does not make sense without nub`arg`"
149149
end
150150
end
151151

@@ -161,8 +161,8 @@ def assert_env_var(key, value)
161161
def assert_command(key, value)
162162
assert_hash key, value, keys: Script::Command.option_keys
163163

164-
refute value['commands'] && value['args'], "#{key} cannot have both commands and args"
165-
refute value['commands'] && value['catch_all'], "#{key} cannot have both commands and catch_all"
164+
refute value['commands'] && value['args'], "#{key} cannot have both nub`commands` and nub`args`"
165+
refute value['commands'] && value['catch_all'], "#{key} cannot have both nub`commands` and nub`catch_all`"
166166

167167
assert_string "#{key}.name", value['name']
168168
assert_optional_string "#{key}.help", value['help']
@@ -209,7 +209,7 @@ def assert_command(key, value)
209209
end
210210

211211
if value['expose']
212-
assert value['commands'], "#{key}.expose makes no sense without commands"
212+
assert value['commands'], "#{key}.expose makes no sense without nub`commands`"
213213
end
214214

215215
if key == 'root'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#<Bashly::ConfigurationError: root cannot have both commands and catch_all>
1+
#<Bashly::ConfigurationError: root cannot have both nub`commands` and nub`catch_all`>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#<Bashly::ConfigurationError: root.commands[0].expose makes no sense without commands>
1+
#<Bashly::ConfigurationError: root.commands[0].expose makes no sense without nub`commands`>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#<Bashly::ConfigurationError: root cannot have both commands and args>
1+
#<Bashly::ConfigurationError: root cannot have both nub`commands` and nub`args`>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#<Bashly::ConfigurationError: root.flags[0] cannot have both allowed and completions>
1+
#<Bashly::ConfigurationError: root.flags[0] cannot have both nub`allowed` and nub`completions`>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#<Bashly::ConfigurationError: root.flags[0].allowed does not make sense without arg>
1+
#<Bashly::ConfigurationError: root.flags[0].allowed does not make sense without nub`arg`>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#<Bashly::ConfigurationError: root.flags[0].completions does not make sense without arg>
1+
#<Bashly::ConfigurationError: root.flags[0].completions does not make sense without nub`arg`>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#<Bashly::ConfigurationError: root.flags[0].default does not make sense without arg>
1+
#<Bashly::ConfigurationError: root.flags[0].default does not make sense without nub`arg`>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#<Bashly::ConfigurationError: root.flags[0] cannot have both required and default>
1+
#<Bashly::ConfigurationError: root.flags[0] cannot have both nub`required` and nub`default`>

0 commit comments

Comments
 (0)