Skip to content

Commit 374db71

Browse files
committed
validate catch_all hash and reduce Command#catch_all_label cognitive complexity
1 parent 2909dcc commit 374db71

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/bashly/config_validator.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ def assert_catch_all(key, value)
5656
return unless value
5757
assert [TrueClass, String, Hash].include?(value.class),
5858
"#{key} must be a boolean, a string or a hash"
59+
60+
assert_catch_all_hash key, value if value.is_a? Hash
61+
end
62+
63+
def assert_catch_all_hash(key, value)
64+
assert_string "#{key}.label", value['label']
65+
assert_optional_string "#{key}.help", value['help']
66+
assert_boolean "#{key}.required", value['required']
5967
end
6068

6169
def assert_extensible(key, value)

lib/bashly/script/command.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ def catch_all_label
3636

3737
if catch_all.is_a? String
3838
"#{catch_all.upcase}..."
39-
elsif catch_all.is_a?(Hash) and catch_all['label'].is_a?(String)
39+
elsif catch_all.is_a?(Hash)
4040
"#{catch_all['label'].upcase}..."
4141
else
4242
"..."
4343
end
4444
end
4545

46-
# Returns a used defined help string for the catch_all directive
46+
# Returns a user defined help string for the catch_all directive
4747
def catch_all_help
4848
return nil unless catch_all
4949

0 commit comments

Comments
 (0)