Module: RHC::Commands

Defined in:
lib/rhc/commands.rb,
lib/rhc/commands/app.rb,
lib/rhc/commands/env.rb,
lib/rhc/commands/scp.rb,
lib/rhc/commands/ssh.rb,
lib/rhc/commands/apps.rb,
lib/rhc/commands/logs.rb,
lib/rhc/commands/show.rb,
lib/rhc/commands/stop.rb,
lib/rhc/commands/tail.rb,
lib/rhc/commands/team.rb,
lib/rhc/commands/tidy.rb,
lib/rhc/commands/alias.rb,
lib/rhc/commands/clone.rb,
lib/rhc/commands/setup.rb,
lib/rhc/commands/start.rb,
lib/rhc/commands/create.rb,
lib/rhc/commands/delete.rb,
lib/rhc/commands/deploy.rb,
lib/rhc/commands/domain.rb,
lib/rhc/commands/logout.rb,
lib/rhc/commands/member.rb,
lib/rhc/commands/reload.rb,
lib/rhc/commands/server.rb,
lib/rhc/commands/sshkey.rb,
lib/rhc/commands/account.rb,
lib/rhc/commands/restart.rb,
lib/rhc/commands/snapshot.rb,
lib/rhc/commands/cartridge.rb,
lib/rhc/commands/configure.rb,
lib/rhc/commands/git_clone.rb,
lib/rhc/commands/deployment.rb,
lib/rhc/commands/force_stop.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, Clone, Configure, Create, Delete, Deploy, Deployment, Domain, Env, ForceStop, ForwardingSpec, GitClone, Logout, Logs, Member, PortForward, Reload, Restart, Scp, Server, Setup, Show, Snapshot, Ssh, Sshkey, Start, Stop, Tail, Team, Threaddump, Tidy

Class Method Summary collapse

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 = "app #{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)
  global_options << [args.freeze, block]
end

.loadObject



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, options, config)
  if not (cmd.class.suppress_wizard? or
          options.noprompt or
          options.help or
          config.has_local_config? or
          config.has_opts_config?)

    $stderr.puts RHC::Helpers.color("You have not yet configured the CloudStrap client tools. Please run 'app 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)
  global_options.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 |meta|
        switches = meta[:switches]
        unless switches.blank?
          switches = switches.dup
          switches << meta[:description]
          switches << meta.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, options|
        deprecated!

        config = c.instance_variable_get(:@config)

        cmd = opts[:class].new
        cmd.options = options
        cmd.config = config

        args = fill_arguments(cmd, options, , , args)
        needs_configuration!(cmd, options, config)

        return execute(cmd, :help, args) unless opts[:method]
        execute(cmd, opts[:method], args)
      end
    end
  end
  self
end