class Fuelcell::Action::OptDefinition
Responsible for defining all the information about an option so that the parser will be able to find it and its values when processing the command line.
Constants
- NO_DEFAULT_ASSIGNED
Attributes
cli_labels[R]
cli_names[R]
cmd_path[R]
default[R]
flag[R]
flag?[R]
global[R]
global?[R]
long[R]
name[R]
names[R]
required[R]
required?[R]
short[R]
type[R]
Public Class Methods
new(text, config = {})
click to toggle source
# File lib/fuelcell/action/opt_definition.rb, line 19 def initialize(text, config = {}) initialize_names(text) @flag = config[:flag] == true ? true : false @required = config[:required] == true ? true : false @global = config[:global] == true ? true : false @type = validate_type(config[:type]) @default = config.fetch(:default) { NO_DEFAULT_ASSIGNED } @banner = config[:banner] || '' @cmd_path = config[:cmd_path] callable config[:run] if config.key?(:run) end
Public Instance Methods
cmd_path?()
click to toggle source
# File lib/fuelcell/action/opt_definition.rb, line 39 def cmd_path? !cmd_path.nil? end
default?()
click to toggle source
# File lib/fuelcell/action/opt_definition.rb, line 31 def default? @default == NO_DEFAULT_ASSIGNED ? false : true end
name?(value)
click to toggle source
# File lib/fuelcell/action/opt_definition.rb, line 35 def name?(value) names.include?(value) end
Private Instance Methods
initialize_long_name(long_name)
click to toggle source
# File lib/fuelcell/action/opt_definition.rb, line 54 def initialize_long_name(long_name) label = "--#{long_name}" @cli_labels << label @names += [long_name, label] end
initialize_names(text)
click to toggle source
# File lib/fuelcell/action/opt_definition.rb, line 45 def initialize_names(text) @name, @long, @short = Parser::OptNameHandler.new.call(text) @cli_labels = [] @names = [name] initialize_short_name(short) if short initialize_long_name(long) if long @cli_names = cli_labels.join(' ') end
initialize_short_name(short_name)
click to toggle source
# File lib/fuelcell/action/opt_definition.rb, line 60 def initialize_short_name(short_name) label = "-#{short_name}" @cli_labels << label @names += [short_name, label] end
validate_type(value)
click to toggle source
# File lib/fuelcell/action/opt_definition.rb, line 66 def validate_type(value) case value.to_s.to_sym when :string, :text, :"" then :string when :number, :numeric then :numeric when :boolean, :bool then :bool when :hash then :hash when :array then :array else fail ArgumentError, "invalid type #{value}" end end