bin/emu_ctl in emu_ctl-0.0.2 vs bin/emu_ctl in emu_ctl-0.0.3

- old
+ new

@@ -11,57 +11,69 @@ usage = " Usage: #{File.basename($0)} list prints all available emulators #{File.basename($0)} running shows all running emulators - #{File.basename($0)} kill kills all running emulators + #{File.basename($0)} kill (ID|all) kills the emulator with ID (see `running`) or all runnig emulators #{File.basename($0)} launch ID runs the emulator with ID, ID is an integer form the output of `list` #{File.basename($0)} targets shows all possible targets and skins, will only display targets with abi #{File.basename($0)} new ID SKIN creates a new avd with API level according to ID and skin SKIN check `targets` for possible values (depends on installed sdk packages) Only works for targets with default abi - #{File.basename($0)} rm ID deletes avd with ID returned in list" + #{File.basename($0)} rm ID deletes avd with ID returned in list + #{File.basename($0)} force-kill sends `kill -9` to all running emulator processes, BE CAREFUL" # command line args if ARGV.empty? puts "You need to specify an action" puts "#{usage}" - exit(2) + exit 2 end action = ARGV.shift case action when 'kill' - pids = EmuCtl::Emulator.running_pids + arg = ARGV.shift + raise 'you need to specify which emulator to kill' if arg.nil? + running = emus = EmuCtl::ADB.devices + targets = arg == 'all' ? running : [ running[arg.to_i] ] + puts "trying to kill emulators: \n\t#{targets.join('\n\t')}" + targets.each{ |t| EmuCtl::ADB.kill_emu(t.qualifier)} + puts "done killing" + when 'force-kill' + warn "dont' use `force-kill` if you don't have to, it might coase android to leave some trash in /tmp/android-[user]/" + pids = EmuCtl::Ctl.running_pids puts "found running emulators with pid: #{pids}" - EmuCtl::Emulator.kill_all + EmuCtl::Ctl.kill_pids(pids) puts "killed all emulators" when 'list' - emus = EmuCtl::Emulator.list - puts emus.map{ |o| "#{emus.index(o)} - #{o.to_s}" }.join("\n") + avds = EmuCtl::Ctl.list + puts avds.map{ |o| "#{avds.index(o)} - #{o.to_s}" }.join("\n") when 'launch' raise "you need to specify the emulator id\n#{usage}" if ARGV.empty? index = ARGV.shift.to_i - emu = EmuCtl::Emulator.list[index] - EmuCtl::Emulator.start(emu) + avd = EmuCtl::Ctl.list[index] + EmuCtl::Ctl.start(avd) when 'targets' - targets = EmuCtl::Emulator.list_targets + targets = EmuCtl::Ctl.list_targets puts targets.map{ |o| "#{targets.index(o)} - #{o.to_s}" }.join("\n") when 'new' target_index = ARGV.shift.to_i skin = ARGV.shift raise "you need to specify target and skin" if target_index.nil? || skin.nil? - target = EmuCtl::Emulator.list_targets[target_index] + target = EmuCtl::Ctl.list_targets[target_index] puts "creating new avd from #{target.id} with skin #{skin}" - EmuCtl::Emulator.create(target, skin) + EmuCtl::Ctl.create(target, skin) when 'running' - puts EmuCtl::ADB.devices + emus = EmuCtl::ADB.devices + puts emus.map{ |o| "#{emus.index(o)} - #{o.to_s}" }.join("\n") when 'rm' emu_index = ARGV.shift raise 'you need to specify the emulator id' if emu_index.nil? - emu = EmuCtl::Emulator.list[Integer(emu_index)] - puts "deleting: #{emu}" - EmuCtl::Emulator.delete(emu) + avd = EmuCtl::Ctl.list[Integer(emu_index)] + puts "deleting: #{avd}" + EmuCtl::Ctl.delete(avd) else - raise "unknown action #{action}\n#{usage}" + puts "unknown action #{action}\n#{usage}" end +exit 0