Class: Replicant::REPL

Inherits:
Object
  • Object
show all
Includes:
Styles
Defined in:
lib/replicant/repl.rb

Constant Summary collapse

ADB_COMMANDS =

for auto-complete via rlwrap; should probably go in Rakefile at some point

%w(devices connect disconnect push pull sync shell emu logcat
forward jdwp install uninstall bugreport backup restore help version
wait-for-device start-server kill-server get-state get-serialno get-devpath
status-window remount reboot reboot-bootloader root usb tcpip ppp)

Constants included from Styles

Styles::CONSOLE_WIDTH, Styles::REPL_OUT, Styles::STYLES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Styles

#create_style, #end_style, #styled_text

Constructor Details

#initializeREPL

Returns a new instance of REPL.



21
22
# File 'lib/replicant/repl.rb', line 21

def initialize
end

Instance Attribute Details

#default_deviceObject

Returns the value of attribute default_device.



19
20
21
# File 'lib/replicant/repl.rb', line 19

def default_device
  @default_device
end

#default_packageObject

Returns the value of attribute default_package.



18
19
20
# File 'lib/replicant/repl.rb', line 18

def default_package
  @default_package
end

Instance Method Details

#command_loopObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/replicant/repl.rb', line 55

def command_loop
  print prompt

  begin
    command_line = $stdin.gets.chomp
  rescue NoMethodError, Interrupt
    exit
  end

  return if command_line.strip.empty?

  command = Command.load(self, command_line)
  if command
    command.execute
    puts styled_text("OK.", :white_fg, :bold)
  else
    output "No such command"
  end
end

#debug?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/replicant/repl.rb', line 79

def debug?
  ARGV.include?('--debug')
end

#output(msg) ⇒ Object



75
76
77
# File 'lib/replicant/repl.rb', line 75

def output(msg)
  puts styled_text(msg, *REPL_OUT)
end

#runObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/replicant/repl.rb', line 24

def run
  # must be the first thing to execute, since it wraps the script
  setup_rlwrap

  show_greeting
  if ARGV.any? { |arg| %w( -h --help -help help ).include?(arg) }
    show_help
  end

  # try to detect a default package to work with from an AndroidManifest
  # file somewhere close by
  if manifest_path = detect_android_manifest_path
    app_package = get_package_from_manifest(manifest_path)
    PackageCommand.new(self, app_package).execute
  end

  # try to pre-select a device, if any
  connected_devices = DevicesCommand.new(self, nil, :silent => true).execute
  if connected_devices.any?
    output "Found #{connected_devices.size} device(s)"
    DeviceCommand.new(self, "1").execute
  end

  # reset terminal colors on exit
  at_exit { puts end_style }

  loop do
    command_loop
  end
end