class RHC::Commands::Base
Attributes
config[RW]
options[RW]
Public Class Methods
new(options=Commander::Command::Options.new, config=RHC::Config.new)
click to toggle source
# File lib/rhc/commands/base.rb, line 14 def initialize(options=Commander::Command::Options.new, config=RHC::Config.new) @options, @config = options, config end
Protected Class Methods
alias_action(action, options={})
click to toggle source
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 132 def self.alias_action(action, options={}) options[:action] = action.is_a?(Array) ? action : action.to_s.split(' ') aliases << options end
argument(name, description, switches=[], options={})
click to toggle source
# File lib/rhc/commands/base.rb, line 149 def self.argument(name, description, switches=[], options={}) arg_type = options[:type] option_symbol = Commander::Runner.switch_to_sym(switches.last) args_metadata << {:name => name, :description => description, :switches => switches, :option_symbol => option_symbol, :covered_by => options[:covered_by], :optional => options[:optional], :default => options[:default], :allow_nil => options[:allow_nil], :hide => options[:hide], :type => arg_type} end
default_action(action)
click to toggle source
# File lib/rhc/commands/base.rb, line 165 def self.default_action(action) options[:default] = action unless action == :help name = self.object_name raise InvalidCommand, "object_name must be set" if name.empty? RHC::Commands.add((@options || {}).merge({ :name => name, :class => self, :method => options[:default] })); end
description(*args)
click to toggle source
# File lib/rhc/commands/base.rb, line 99 def self.description(*args) o = args.join(' ') options[:description] = o.strip_heredoc end
method_added(method)
click to toggle source
# File lib/rhc/commands/base.rb, line 69 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
object_name(value=nil)
click to toggle source
# File lib/rhc/commands/base.rb, line 90 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
option(switches, description, options={})
click to toggle source
# File lib/rhc/commands/base.rb, line 137 def self.option(switches, description, options={}) options_metadata << {:switches => switches, :description => description, :required => options[:required], :covered_by => options[:covered_by], :deprecated => options[:deprecated], :type => options[:type], :hide => options[:hide], :default => options[:default], } end
summary(value)
click to toggle source
# File lib/rhc/commands/base.rb, line 104 def self.summary(value) options[:summary] = value end
suppress_wizard()
click to toggle source
def self.deprecated(msg)
options[:deprecated] = msg
end
# File lib/rhc/commands/base.rb, line 115 def self.suppress_wizard @suppress_wizard = true end
suppress_wizard?()
click to toggle source
# File lib/rhc/commands/base.rb, line 119 def self.suppress_wizard? @suppress_wizard end
syntax(value)
click to toggle source
# File lib/rhc/commands/base.rb, line 108 def self.syntax(value) options[:syntax] = value end
Private Class Methods
aliases()
click to toggle source
# File lib/rhc/commands/base.rb, line 184 def self.aliases options[:aliases] ||= [] end
args_metadata()
click to toggle source
# File lib/rhc/commands/base.rb, line 181 def self.args_metadata options[:args] ||= [] end
options()
click to toggle source
# File lib/rhc/commands/base.rb, line 187 def self.options @options ||= {} end
options_metadata()
click to toggle source
# File lib/rhc/commands/base.rb, line 178 def self.options_metadata options[:options] ||= [] end
Protected Instance Methods
help(*args)
click to toggle source
# File lib/rhc/commands/base.rb, line 63 def help(*args) raise ArgumentError, "Please specify an action to take" end
rest_client(opts={})
click to toggle source
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 30 def rest_client(opts={}) @rest_client ||= begin core_auth = if (options.ssl_client_cert_file && options.ssl_client_key_file) RHC::Auth::X509.new(options) else RHC::Auth::Basic.new(options) end # Specifying a username and password on the CLI trumps token # authentication. auth = if options.rhlogin && options.password RHC::Auth::Basic.new(options) elsif (options.use_authorization_tokens || options.token) RHC::Auth::Token.new(options, core_auth, token_store) else core_auth end 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
token_store()
click to toggle source
# File lib/rhc/commands/base.rb, line 59 def token_store @token_store ||= RHC::Auth::TokenStore.new(config.home_conf_path) end