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



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

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



123
124
125
# File 'lib/hammer_cli/options/normalizers.rb', line 123

def completion_type
  :list
end

Instance Method Details

#format(val) ⇒ Object



134
135
136
137
138
139
140
141
# File 'lib/hammer_cli/options/normalizers.rb', line 134

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