Class: Gem::Portage::Command
Direct Known Subclasses
Defined Under Namespace
Classes: Option
Class Method Summary collapse
- .class_command_options ⇒ Object
- .has_option(id, *getopt_args, &handler) ⇒ Object
- .has_options_from(other, *opts) ⇒ Object
- .register ⇒ Object
Instance Method Summary collapse
- #class_command_options(*args, &prc) ⇒ Object
- #defaults_str ⇒ Object
-
#initialize(command, summary = nil, defaults = nil) ⇒ Command
constructor
A new instance of Command.
- #register ⇒ Object
Constructor Details
#initialize(command, summary = nil, defaults = nil) ⇒ Command
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/g-gem/command.rb', line 4 def initialize(command, summary=nil, defaults=nil) super(command, summary, defaults || {}) = {} .each_pair do |k, option| add_option(*option.optparse_args, &option.handler) [option.opt_id] = option.default unless option.default.nil? extend option.module end self.defaults = unless defaults end |
Class Method Details
.class_command_options ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/g-gem/command.rb', line 50 def ||= if superclass.respond_to?(:class_command_options) superclass..dup else {} end end |
.has_option(id, *getopt_args, &handler) ⇒ Object
30 31 32 33 |
# File 'lib/g-gem/command.rb', line 30 def has_option(id, *getopt_args, &handler) option = Option.new(id, *getopt_args, &handler) [option.opt_id] = option end |
.has_options_from(other, *opts) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/g-gem/command.rb', line 35 def (other, *opts) defaults = Hash === opts.last ? opts.pop : {} borrowed = opts.empty? ? other..keys : opts + defaults.keys borrowed.each do |key| next unless key opt = other.[key].dup opt.default = defaults[key] if defaults.has_key? key [opt.opt_id] = opt end end |
.register ⇒ Object
46 47 48 |
# File 'lib/g-gem/command.rb', line 46 def register new.register end |
Instance Method Details
#class_command_options(*args, &prc) ⇒ Object
25 26 27 |
# File 'lib/g-gem/command.rb', line 25 def (*args, &prc) self.class.(*args, &prc) end |
#defaults_str ⇒ Object
15 16 17 18 19 |
# File 'lib/g-gem/command.rb', line 15 def defaults_str defaults.keys.inject("") do |str, opt| str + " " + [opt].to_s end end |
#register ⇒ Object
21 22 23 |
# File 'lib/g-gem/command.rb', line 21 def register command_manager.register_command self end |