Module: RHC::Commands
- Defined in:
- lib/rhc/commands.rb,
lib/rhc/commands/app.rb,
lib/rhc/commands/env.rb,
lib/rhc/commands/ssh.rb,
lib/rhc/commands/apps.rb,
lib/rhc/commands/tail.rb,
lib/rhc/commands/alias.rb,
lib/rhc/commands/setup.rb,
lib/rhc/commands/domain.rb,
lib/rhc/commands/logout.rb,
lib/rhc/commands/member.rb,
lib/rhc/commands/server.rb,
lib/rhc/commands/sshkey.rb,
lib/rhc/commands/account.rb,
lib/rhc/commands/snapshot.rb,
lib/rhc/commands/cartridge.rb,
lib/rhc/commands/git_clone.rb,
lib/rhc/commands/deployment.rb,
lib/rhc/commands/threaddump.rb,
lib/rhc/commands/port_forward.rb,
lib/rhc/commands/authorization.rb
Defined Under Namespace
Classes: Account, Alias, App, Apps, Authorization, Base, Cartridge, Deployment, Domain, Env, ForwardingSpec, GitClone, Logout, Member, PortForward, Server, Setup, Snapshot, Ssh, Sshkey, Tail, Threaddump
Class Method Summary collapse
- .add(opts) ⇒ Object
- .deprecated! ⇒ Object
- .global_option(*args, &block) ⇒ Object
- .load ⇒ Object
- .needs_configuration!(cmd, options, config) ⇒ Object
- .to_commander(instance = Commander::Runner.instance) ⇒ Object
Class Method Details
.add(opts) ⇒ Object
184 185 186 |
# File 'lib/rhc/commands.rb', line 184 def self.add(opts) commands[opts[:name]] = opts end |
.deprecated! ⇒ Object
191 192 193 194 195 196 197 198 199 200 |
# File 'lib/rhc/commands.rb', line 191 def self.deprecated! instance = Commander::Runner.instance command_name = instance.command_name_from_args command = instance.active_command if new_cmd = command.deprecated(command_name) new_cmd = "pbox #{command.name}" if new_cmd == true RHC::Helpers.deprecated_command new_cmd end end |
.global_option(*args, &block) ⇒ Object
187 188 189 |
# File 'lib/rhc/commands.rb', line 187 def self.global_option(*args, &block) << [args.freeze, block] end |
.load ⇒ Object
178 179 180 181 182 183 |
# File 'lib/rhc/commands.rb', line 178 def self.load Dir[File.join(File.dirname(__FILE__), "commands", "*.rb")].each do |file| require file end self end |
.needs_configuration!(cmd, options, config) ⇒ Object
202 203 204 205 206 207 208 209 210 211 |
# File 'lib/rhc/commands.rb', line 202 def self.needs_configuration!(cmd, , config) if not (cmd.class.suppress_wizard? or .noprompt or .help or config.has_local_config? or config.has_opts_config?) $stderr.puts RHC::Helpers.color("You have not yet configured the ProtonBox client tools. Please run 'pbox setup'.", :yellow) end end |
.to_commander(instance = Commander::Runner.instance) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/rhc/commands.rb', line 213 def self.to_commander(instance=Commander::Runner.instance) .each do |args, block| args = args.dup opts = (args.pop if Hash === args.last) || {} option = instance.global_option(*args, &block).last option.merge!(opts) end commands.each_pair do |name, opts| name = Array(name) names = [name.reverse.join('-'), name.join(' ')] if name.length > 1 name = name.join('-') instance.command name do |c| c.description = opts[:description] c.summary = opts[:summary] c.syntax = opts[:syntax] c.default_action = opts[:default] c.info = opts ( = Array(opts[:options])).each do |o| option_data = [o[:switches], o[:type], o[:description], o.slice(:optional, :default, :hide, :covered_by)].compact.flatten(1) c.option *option_data o[:arg] = Commander::Runner.switch_to_sym(Array(o[:switches]).last) end ( = Array(opts[:args])).each do || switches = [:switches] unless switches.blank? switches = switches.dup switches << [:description] switches << .slice(:optional, :default, :hide, :covered_by, :allow_nil) c.option *switches end end Array(opts[:aliases]).each do |a| action = Array(a[:action]) [' ', '-'].each do |s| cmd = action.join(s) instance.alias_command cmd, name end end if names names.each{ |alt| instance.alias_command alt, name } else c.root = true end c.when_called do |args, | deprecated! config = c.instance_variable_get(:@config) cmd = opts[:class].new cmd. = cmd.config = config args = fill_arguments(cmd, , , , args) needs_configuration!(cmd, , config) return execute(cmd, :help, args) unless opts[:method] execute(cmd, opts[:method], args) end end end self end |