Skip to content

Commit 0c74891

Browse files
committed
- Add command.name validation
1 parent 686ece4 commit 0c74891

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

lib/bashly/config_validator.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ 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_\-]+$/), "#{key}.name must only contain lowercase alphanumeric characters, hyphens and underscores"
161+
refute value['name'].start_with?('-'), "#{key}.name must not start with a hyphen"
162+
160163
assert_array "#{key}.args", value['args'], of: :arg
161164
assert_array "#{key}.flags", value['flags'], of: :flag
162165
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)