Class: Commander::Command
- Defined in:
- lib/rhc/commands.rb,
lib/rhc/commands.rb
Defined Under Namespace
Classes: Options
Instance Attribute Summary collapse
-
#default_action ⇒ Object
Returns the value of attribute default_action.
-
#info ⇒ Object
Returns the value of attribute info.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
- #default_action? ⇒ Boolean
- #deprecated(as_alias = nil) ⇒ Object
- #option(*args, &block) ⇒ Object
- #option_old ⇒ Object
- #parse_options_and_call_procs(*args) ⇒ Object
-
#proxy_option_struct ⇒ Object
Force proxy_option_struct to default to nil for values, backported for Commander 4.0.3.
- #root? ⇒ Boolean
Instance Attribute Details
#default_action ⇒ Object
Returns the value of attribute default_action.
8 9 10 |
# File 'lib/rhc/commands.rb', line 8 def default_action @default_action end |
#info ⇒ Object
Returns the value of attribute info.
8 9 10 |
# File 'lib/rhc/commands.rb', line 8 def info @info end |
Instance Method Details
#default_action? ⇒ Boolean
9 10 11 |
# File 'lib/rhc/commands.rb', line 9 def default_action? default_action.present? end |
#deprecated(as_alias = nil) ⇒ Object
49 50 51 52 53 54 |
# 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 |
#option(*args, &block) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/rhc/commands.rb', line 17 def option(*args, &block) opts = args.pop if Hash === args.last option_old(*args, &block).tap do || .last.merge!(opts) if opts end end |
#option_old ⇒ Object
16 |
# File 'lib/rhc/commands.rb', line 16 alias_method :option_old, :option |
#parse_options_and_call_procs(*args) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rhc/commands.rb', line 56 def *args runner = Commander::Runner.instance opts = OptionParser.new # add global options runner..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 = .find{ |arg| arg[0] == :config } clean, _ = .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..each_pair do |key, value| next if .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 << [key, value] end end end rescue ArgumentError => e n = OptionParser::InvalidOption.new(e.) 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 |
#proxy_option_struct ⇒ Object
Force proxy_option_struct to default to nil for values, backported for Commander 4.0.3
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rhc/commands.rb', line 28 def proxy_option_struct .inject Options.new do |, (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 .select{ |item| item[0] == option }.length > 1 if [option] [option] << value else .__send__ :"#{option}=", [value] end else .__send__ :"#{option}=", value end end end |