class Fuelcell::Parser::ShortOptNoSpaceHandler
Handles short options that express their value without using a space like -uroot where the short opt is -u and value is root
Public Instance Methods
call(cmd, args, opts)
click to toggle source
@param cmd [Fuelcell::Command] @param args [Array] raw args from ARGV @param opts [Hash] stores the found opts @return [Boolean]
# File lib/fuelcell/parser/short_opt_no_space_handler.rb, line 10 def call(cmd, args, opts) arg = take_first_arg(args) do |text| !(text =~ /^-([a-zA-Z]{2,})$/).nil? end return false unless arg return true if handle_no_space_value(cmd, opts, args, arg) arg[0] = '' # remove the dash handle_cluster(cmd, opts, arg) true end
Private Instance Methods
handle_cluster(cmd, opts, arg)
click to toggle source
# File lib/fuelcell/parser/short_opt_no_space_handler.rb, line 42 def handle_cluster(cmd, opts, arg) cluster = arg.split('') cluster.each do |short| opt = cmd.find_opt("-#{short}") unless opt.flag? fail "-#{short} can not live in a cluster, it must be a flag" end found_opt_flag(opts, opt) end end
handle_no_space_value(cmd, opts, args, arg)
click to toggle source
we need to determine if this is a short opt with a value smushed into it or a cluster of opts
# File lib/fuelcell/parser/short_opt_no_space_handler.rb, line 28 def handle_no_space_value(cmd, opts, args, arg) name = "-#{arg[1]}" value = arg.slice(2, arg.size) opt = cmd.find_opt(name) fail "#{name} is not a registered option" unless opt unless opt.flag? assign_opt_value(opts, opt, value, name) return true end false end