Skip to content

Commit cffa59c

Browse files
authored
Merge pull request #345 from DannyBen/add/command-name-validation
Add command.name validation
2 parents 686ece4 + 536681c commit cffa59c

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

lib/bashly/config_validator.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ def assert_command(key, value)
157157
assert_extensible "#{key}.extensible", value['extensible']
158158
assert_dependencies "#{key}.dependencies", value['dependencies']
159159

160+
assert value['name'].match(/^[a-z0-9_-]+$/),
161+
"#{key}.name must only contain lowercase alphanumeric characters, hyphens and underscores"
162+
163+
refute value['name'].start_with?('-'), "#{key}.name must not start with a hyphen"
164+
160165
assert_array "#{key}.args", value['args'], of: :arg
161166
assert_array "#{key}.flags", value['flags'], of: :flag
162167
assert_array "#{key}.commands", value['commands'], of: :command
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Bashly::ConfigurationError: root.name must not start with a hyphen>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Bashly::ConfigurationError: root.name must only contain lowercase alphanumeric characters, hyphens and underscores>

spec/fixtures/script/validations.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@
109109
help: command.function must match /[a-z0-9_]+/
110110
function: myCamelCaseFunction
111111

112+
:command_name_uppercase:
113+
name: INVALID
114+
help: command.name must match /[a-z0-9_\-]+/
115+
116+
:command_name_hyphen:
117+
name: -invalid
118+
help: command.name must not start with a hyphen
119+
112120
:command_version:
113121
name: invalid
114122
help: version should be a string or a number

0 commit comments

Comments
 (0)