# File lib/rhc/commands/base.rb, line 14 def initialize(options=Commander::Command::Options.new, config=RHC::Config.new) @options, @config = options, config end
Provide an alias to the command. The alias will not be shown in help, but will be available in autocompletion and at execution time.
Supported options:
:deprecated - if true, a warning will be displayed when the command is executed :root_command - if true, do not prepend the object name to the command
# File lib/rhc/commands/base.rb, line 125 def self.alias_action(action, options={}) options[:action] = action.is_a?(Array) ? action : action.to_s.split(' ') aliases << options end
# File lib/rhc/commands/base.rb, line 139 def self.argument(name, description, switches=[], options={}) arg_type = options[:arg_type] 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, :optional => options[:optional], :arg_type => arg_type} end
# File lib/rhc/commands/base.rb, line 152 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 105 def self.deprecated(msg) options[:deprecated] = msg end
# File lib/rhc/commands/base.rb, line 95 def self.description(*args) o = args.join(' ') options[:description] = o.strip_heredoc end
# File lib/rhc/commands/base.rb, line 60 def self.inherited(klass) unless klass == RHC::Commands::Base end end
# File lib/rhc/commands/base.rb, line 65 def self.method_added(method) return if self == RHC::Commands::Base return if private_method_defined? method return if protected_method_defined? method prefix = self.object_name method_name = method.to_s == 'run' ? nil : method.to_s.gsub("_", "-") name = [prefix, method_name].compact raise InvalidCommand, "Either object_name must be set or a non default method defined" if name.empty? aliases.each{ |a| a[:action].unshift(prefix) unless a[:root_command] } if prefix RHC::Commands.add((@options || {}).merge({ :name => name, :class => self, :method => method })); @options = nil end
# File lib/rhc/commands/base.rb, line 86 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(/(?=[A-Z])/).join('-').downcase if value end end
# File lib/rhc/commands/base.rb, line 130 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 99 def self.summary(value) options[:summary] = value end
# File lib/rhc/commands/base.rb, line 108 def self.suppress_wizard @suppress_wizard = true end
# File lib/rhc/commands/base.rb, line 112 def self.suppress_wizard? @suppress_wizard end
# File lib/rhc/commands/base.rb, line 102 def self.syntax(value) options[:syntax] = value end
# File lib/rhc/commands/base.rb, line 164 def self.aliases options[:aliases] ||= [] end
# File lib/rhc/commands/base.rb, line 161 def self.args_metadata options[:args] ||= [] end
# File lib/rhc/commands/base.rb, line 167 def self.options @options ||= {} end
# File lib/rhc/commands/base.rb, line 158 def self.options_metadata options[:options] ||= [] end
# File lib/rhc/commands/base.rb, line 54 def debug? @options.debug end
# File lib/rhc/commands/base.rb, line 50 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) if (options.use_authorization_tokens || options.token) && !(options.rhlogin && options.password) debug "Authenticating with #{auth.class}" client_from_options(:auth => auth) end if opts[:min_api] && opts[:min_api].to_f > @rest_client.api_version_negotiated.to_f raise RHC::ServerAPINotSupportedException.new(opts[:min_api], @rest_client.api_version_negotiated) end @rest_client end
# File lib/rhc/commands/base.rb, line 46 def token_store @token_store ||= RHC::Auth::TokenStore.new(config.home_conf_path) end