class HammerCLI::Options::Normalizers::EnumList

Attributes

allowed_values[R]

Public Class Methods

common_description() click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 383
def common_description
  _("Any combination of possible values described in the option's description")
end
completion_type() click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 379
def completion_type
  :multienum
end
new(allowed_values) click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 390
def initialize(allowed_values)
  @allowed_values = allowed_values
end

Public Instance Methods

complete(value) click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 402
def complete(value)
  Completer::finalize_completions(@allowed_values)
end
completion_type() click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 406
def completion_type
  super.merge({ values: allowed_values })
end
description() click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 394
def description
  _("Any combination (comma separated list) of '%s'") % quoted_values
end
format(value) click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 398
def format(value)
  value.is_a?(String) ? parse(value) : []
end

Private Instance Methods

parse(arr) click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 416
def parse(arr)
  arr.split(",").uniq.tap do |values|
    unless values.inject(true) { |acc, cur| acc & (@allowed_values.include? cur) }
      raise ArgumentError, _("Value must be a combination of '%s'.") % quoted_values
    end
  end
end
quoted_values() click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 412
def quoted_values
  @allowed_values.map { |v| "'#{v}'" }.join(', ')
end