# File lib/rhc/commands.rb, line 9 def default_action? default_action.present? end
# File lib/rhc/commands.rb, line 49 def deprecated(as_alias=nil) return false unless info return info[:deprecated] if info[:deprecated] return false unless info[:aliases] info[:aliases].select{ |a| ['-',' '].map{ |s| Array(a[:action]).join(s) }.include?(as_alias) }.map{ |a| a[:deprecated] }.first if as_alias end
# File lib/rhc/commands.rb, line 17 def option(*args, &block) opts = args.pop if Hash === args.last option_old(*args, &block).tap do |options| options.last.merge!(opts) if opts end end
# File lib/rhc/commands.rb, line 56 def parse_options_and_call_procs *args runner = Commander::Runner.instance opts = OptionParser.new # add global options runner.options.each do |option| opts.on(*option[:args], &runner.global_option_proc(option[:switches], &option[:proc])) end # add command options @options.each do |option| opts.on(*option[:args], &option[:proc]) opts end # Separate option lists with '--' remaining = args.split('--').map{ |a| opts.parse!(a) }.inject([]) do |arr, h| arr << '--' arr.concat(h) end remaining.shift _, config_path = proxy_options.find{ |arg| arg[0] == :config } clean, _ = proxy_options.find{ |arg| arg[0] == :clean } begin @config = RHC::Config.new @config.use_config(config_path) if config_path $terminal.debug("Using config file #{@config.config_path}") unless clean @config.to_options.each_pair do |key, value| next if proxy_options.detect{ |arr| arr[0] == key } if sw = opts.send(:search, :long, key.to_s.gsub(/_/, '-')) _, cb, val = sw.send(:conv_arg, nil, value) {|*exc| raise(*exc) } cb.call(val) if cb else proxy_options << [key, value] end end end rescue ArgumentError => e n = OptionParser::InvalidOption.new(e.message) n.reason = "The configuration file #{@config.path} contains an invalid setting" n.set_backtrace(e.backtrace) raise n rescue OptionParser::ParseError => e e.reason = "The configuration file #{@config.path} contains an invalid setting" raise end remaining end
Force #proxy_option_struct to default to nil for values, backported for Commander 4.0.3
# File lib/rhc/commands.rb, line 28 def proxy_option_struct proxy_options.inject Options.new do |options, (option, value)| # options that are present will evaluate to true value = true if value.nil? # if multiple values were specified for this option, collect it as an # array. on 'fill_arguments' we will decide between stick with the array # (if :type => :list) or just take the last value from array. # not part of the backported method. if proxy_options.select{ |item| item[0] == option }.length > 1 if options[option] options[option] << value else options.__send__ :"#{option}=", [value] end else options.__send__ :"#{option}=", value end options end end
# File lib/rhc/commands.rb, line 12 def root? root.present? end