class Command

Attributes

args[R]

Public Class Methods

all() click to toggle source
# File lib/replicant/commands/command.rb, line 12
def self.all
  (@@subclasses - [AdbCommand, ListCommand, EnvCommand]).map do |clazz|
    clazz.new(nil)
  end
end
inherited(subclass) click to toggle source
# File lib/replicant/commands/command.rb, line 7
def self.inherited(subclass)
  @@subclasses ||= []
  @@subclasses << subclass
end
load(repl, command_line) click to toggle source
# File lib/replicant/commands/command.rb, line 18
def self.load(repl, command_line)
  if command_line == '!'
    # load command that lists available commands
    ListCommand.new(repl)
  elsif command_line == '?'
    EnvCommand.new(repl)
  elsif command_line.start_with?('!')
    # load custom command
    command_parts = command_line[1..-1].split
    command_name = command_parts.first
    command_args = command_parts[1..-1].join(' ')
    command_class = "#{command_name.capitalize}Command"
    begin
      clazz = Object.const_get(command_class)
      clazz.new(repl, command_args)
    rescue NameError => e
      nil
    end
  else
    # forward command to ADB
    AdbCommand.new(repl, command_line.strip)
  end
end
new(repl, args = nil, options = {}) click to toggle source
# File lib/replicant/commands/command.rb, line 44
def initialize(repl, args = nil, options = {})
  @repl = repl
  @args = args.strip if args
  @options = options
end

Public Instance Methods

description() click to toggle source

subclasses override this to provide a description of their functionality

# File lib/replicant/commands/command.rb, line 55
def description
  "TODO: description missing"
end
execute() click to toggle source
# File lib/replicant/commands/command.rb, line 63
def execute
  if valid_args?
    run
  else
    output "Invalid arguments. Ex.: #{usage}"
  end
end
name() click to toggle source
# File lib/replicant/commands/command.rb, line 50
def name
  "!#{self.class.name.gsub("Command", "").downcase}"
end
usage() click to toggle source

subclasses override this to provide a usage example

# File lib/replicant/commands/command.rb, line 60
def usage
end

Private Instance Methods

output(message) click to toggle source
# File lib/replicant/commands/command.rb, line 77
def output(message)
  @repl.output(message) unless @options[:silent]
end
putsd(message) click to toggle source
# File lib/replicant/commands/command.rb, line 81
def putsd(message)
  puts "[DEBUG] #{message}" if @repl.debug?
end
valid_args?() click to toggle source
# File lib/replicant/commands/command.rb, line 73
def valid_args?
  true
end