# File lib/rhc/commands/base.rb, line 14 def initialize(options=Commander::Command::Options.new, config=RHC::Config.new) @options, @config = options, config end
# File lib/rhc/commands/base.rb, line 111 def self.alias_action(action, options={}) # if it is a root_command we simply alias it to the passed in action # if not we prepend the current resource to the action # default == false options[:root_command] ||= false options[:action] = action options[:deprecated] ||= false aliases << options end
# File lib/rhc/commands/base.rb, line 130 def self.argument(name, description, switches, options={}) arg_type = options[:arg_type] raise ArgumentError("Only the last argument descriptor for an action can be a list") if arg_type == :list and list_argument_defined? list_argument_defined true if arg_type == :list option_symbol = Commander::Runner.switch_to_sym(switches.last) args_metadata << {:name => name, :description => description, :switches => switches, :context_helper => options[:context], :option_symbol => option_symbol, :arg_type => arg_type} end
# File lib/rhc/commands/base.rb, line 144 def self.default_action(action) options[:default] = action unless action == :help define_method(:run) { |*args| send(action, *args) } end
# File lib/rhc/commands/base.rb, line 100 def self.deprecated(msg) options[:deprecated] = msg end
# File lib/rhc/commands/base.rb, line 85 def self.description(*args) o = args.join(' ') indent = o.scan(%r^[ \t]*(?=\S)/).min.size || 0 options[:description] = o.gsub(%r^[ \t]{#{indent}}/, ''). gsub(%r(\b|')\s*\n(?!\s*\n)(\S)/, '\1 \2'). gsub(%r\n+\Z/, ''). gsub(%r\n{3,}/, "\n\n") end
# File lib/rhc/commands/base.rb, line 53 def self.inherited(klass) unless klass == RHC::Commands::Base end end
# File lib/rhc/commands/base.rb, line 58 def self.method_added(method) return if self == RHC::Commands::Base return if private_method_defined? method return if protected_method_defined? method method_name = method.to_s == 'run' ? nil : method.to_s.gsub("_", "-") name = [method_name] name.unshift(self.object_name).compact! raise InvalidCommand, "Either object_name must be set or a non default method defined" if name.empty? RHC::Commands.add((@options || {}).merge({ :name => name.join(' '), :class => self, :method => method })); @options = nil end
# File lib/rhc/commands/base.rb, line 76 def self.object_name(value=nil) @object_name ||= begin value ||= if self.name && !self.name.empty? self.name.split('::').last end value.to_s.split(%r(?=[A-Z])/).join('-').downcase if value end end
# File lib/rhc/commands/base.rb, line 121 def self.option(switches, description, options={}) options_metadata << {:switches => switches, :description => description, :context_helper => options[:context], :required => options[:required], :deprecated => options[:deprecated] } end
# File lib/rhc/commands/base.rb, line 94 def self.summary(value) options[:summary] = value end
# File lib/rhc/commands/base.rb, line 103 def self.suppress_wizard @suppress_wizard = true end
# File lib/rhc/commands/base.rb, line 107 def self.suppress_wizard? @suppress_wizard end
# File lib/rhc/commands/base.rb, line 97 def self.syntax(value) options[:syntax] = value end
# File lib/rhc/commands/base.rb, line 47 def debug? @options.debug end
# File lib/rhc/commands/base.rb, line 43 def help(*args) raise ArgumentError, "Please specify an action to take" end
Return a client object capable of making calls to the OpenShift API that transforms intent and options, to remote calls, and then handle the output (or failures) into exceptions and formatted object output. Most interactions should be through this call pattern.
# File lib/rhc/commands/base.rb, line 31 def rest_client(opts={}) @rest_client ||= begin auth = RHC::Auth::Basic.new(options) auth = RHC::Auth::Token.new(options, auth, token_store) client_from_options(:auth => auth) end end
# File lib/rhc/commands/base.rb, line 39 def token_store @token_store ||= RHC::Auth::TokenStore.new(config.home_conf_path) end