Method: CouchShell::Shell#execute_command!

Defined in:
lib/couch-shell/shell.rb

#execute_command!(commandref, argstr = nil) ⇒ Object



420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
# File 'lib/couch-shell/shell.rb', line 420

def execute_command!(commandref, argstr = nil)
  if commandref.start_with?("@")
    # qualified command
    if commandref =~ /\A@([^\.]+)\.([^\.]+)\z/
      plugin_name = $1
      command_name = $2
      plugin = @plugins[plugin_name]
      raise NoSuchPluginRegistered.new(plugin_name) unless plugin
      ci = plugin.plugin_info.commands[command_name]
      raise NoSuchCommandInPlugin.new(plugin_name, command_name) unless ci
      plugin.send ci.execute_message, argstr
    else
      raise ShellUserError, "invalid command syntax"
    end
  else
    # unqualified command
    ci = @commands[commandref]
    raise NoSuchCommand.new(commandref) unless ci
    @plugins[ci.plugin.plugin_name].send ci.execute_message, argstr
  end
end