Class: HammerCLI::Options::Normalizers::List

Inherits:
AbstractNormalizer show all
Defined in:
lib/hammer_cli/options/normalizers.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractNormalizer

#complete, #completion_type, #description, inherited

Class Method Details

.common_descriptionObject



132
133
134
135
136
# File 'lib/hammer_cli/options/normalizers.rb', line 132

def common_description
  _('Comma separated list of values. Values containing comma should be quoted or escaped with backslash.') +
    "\n" +
    _('JSON is acceptable and preferred way for such parameters')
end

.completion_typeObject



128
129
130
# File 'lib/hammer_cli/options/normalizers.rb', line 128

def completion_type
  :list
end

Instance Method Details

#format(val) ⇒ Object



139
140
141
142
143
144
145
146
# File 'lib/hammer_cli/options/normalizers.rb', line 139

def format(val)
  return [] unless val.is_a?(String) && !val.empty?
  begin
    [JSON.parse(val)].flatten(1)
  rescue JSON::ParserError
    HammerCLI::CSVParser.new.parse(val)
  end
end