Skip to content

Commit 7bb02bc

Browse files
committed
improve flag validations
1 parent c768d0b commit 7bb02bc

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

lib/bashly/config_validator.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def assert_arg(key, value)
8282

8383
assert_array "#{key}.allowed", value['allowed'], of: :string
8484

85-
refute value['name'].match(/^-/), "#{key}.name must not start with a '-'"
85+
refute value['name'].match(/^-/), "#{key}.name must not start with '-'"
8686
end
8787

8888
def assert_flag(key, value)
@@ -99,9 +99,9 @@ def assert_flag(key, value)
9999
assert_boolean "#{key}.required", value['required']
100100
assert_array "#{key}.allowed", value['allowed'], of: :string
101101

102-
assert value['long'].match(/^--[^\s]+$/), "#{key}.long must be in the form of '--name'" if value['long']
103-
assert value['short'].match(/^-[^\s]$/), "#{key}.short must be in the form of '-n'" if value['short']
104-
refute value['arg'].match(/^-/), "#{key}.arg must not start with a '-'" if value['arg']
102+
assert value['long'].match(/^--[a-zA-Z0-9_\-]+$/), "#{key}.long must be in the form of '--name'" if value['long']
103+
assert value['short'].match(/^-[a-zA-Z0-9]$/), "#{key}.short must be in the form of '-n'" if value['short']
104+
refute value['arg'].match(/^-/), "#{key}.arg must not start with '-'" if value['arg']
105105
end
106106

107107
def assert_env_var(key, value)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#<Bashly::ConfigurationError: root.args[0].name must not start with a '-'>
1+
#<Bashly::ConfigurationError: root.args[0].name must not start with '-'>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#<Bashly::ConfigurationError: root.flags[0].arg must not start with a '-'>
1+
#<Bashly::ConfigurationError: root.flags[0].arg must not start with '-'>

0 commit comments

Comments
 (0)