Class: HammerCLI::Options::Normalizers::KeyValueList
- Inherits:
-
AbstractNormalizer
- Object
- AbstractNormalizer
- HammerCLI::Options::Normalizers::KeyValueList
- Defined in:
- lib/hammer_cli/options/normalizers.rb
Constant Summary collapse
- PAIR_RE =
'([^,=]+)=([^,\[]+|\[[^\[\]]*\])'
- FULL_RE =
"^((%s)[,]?)+$" % PAIR_RE
Instance Method Summary collapse
Methods inherited from AbstractNormalizer
Instance Method Details
#description ⇒ Object
33 34 35 |
# File 'lib/hammer_cli/options/normalizers.rb', line 33 def description _("Comma-separated list of key=value") end |
#format(val) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/hammer_cli/options/normalizers.rb', line 37 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 |