Class: HammerCLI::Options::Normalizers::KeyValueList
Constant Summary
collapse
- PAIR_RE =
'([^,=]+)=([^,\{\[]+|[\{\[][^\{\}\[\]]*[\}\]])'
- FULL_RE =
"^((%s)[,]?)+$" % PAIR_RE
Class Method Summary
collapse
Instance Method Summary
collapse
#complete, #completion_type, #description, inherited
Class Method Details
.common_description ⇒ Object
62
63
64
65
|
# File 'lib/hammer_cli/options/normalizers.rb', line 62
def common_description
_('Comma-separated list of key=value.') + "\n" +
_('JSON is acceptable and preferred way for such parameters')
end
|
.completion_type ⇒ Object
58
59
60
|
# File 'lib/hammer_cli/options/normalizers.rb', line 58
def completion_type
:key_value_list
end
|
Instance Method Details
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/hammer_cli/options/normalizers.rb', line 68
def format(val)
return {} unless val.is_a?(String)
return {} if val.empty?
if valid_key_value?(val)
parse_key_value(val)
else
begin
formatter = JSONInput.new
formatter.format(val)
rescue ArgumentError
raise ArgumentError, _("Value must be defined as a comma-separated list of key=value or valid JSON.")
end
end
end
|