bin/instalatron-play in instalatron-0.1.1 vs bin/instalatron-play in instalatron-0.1.2

- old
+ new

@@ -2,15 +2,20 @@ require 'fileutils' require 'instalatron' require 'yaml' require 'mixlib/cli' -def play_session(vm_name, script) +def play_session(vm_name, script, custom_seq = nil) ctrlc_gap = 0 basedir = File.dirname(script) script = YAML.load_file(script) - require 'pp' + if custom_seq + new_seq = script[0] + new_seq[:sequence] = custom_seq + script[0] = new_seq + end + step = 1 script.each do |screen| ref_img = "#{basedir}/#{File.basename(screen[:image])}" loop do begin img = Instalatron.detect_screen(vm_name) @@ -20,18 +25,19 @@ break end rescue Interrupt, SystemExit if Time.now.to_f - ctrlc_gap < 0.5 puts "\n\nDouble Ctrl-c detected. Aborting." - exit + return else ctrlc_gap = Time.now.to_f end puts "Skipping #{screen[:name]}" break end end + step += 1 end end def required_option(cli, opt) if cli.config[opt].nil? @@ -63,11 +69,20 @@ option :script, :short => "-s SCRIPT", :long => "--script SCRIPT", :description => "Path to the script file (script.yml) or directory." + + option :custom_sequence, + :short => "-c SEQUENCE", + :long => "--custom-sequence SEQUENCE", + :description => "Replace first step key sequence" + option :destroy_vm, + :long => "--destroy-vm", + :description => "Destroy the VM after running the tests" + option :help, :short => "-h", :long => "--help", :description => "Show this message", :on => :tail, @@ -101,6 +116,11 @@ # Create VBox VM first Instalatron.create_vm :vm_name => vm_name, :iso_file => iso_file puts "Playing script using VM #{vm_name}\n\n" -play_session vm_name, script +play_session vm_name, script, cli.config[:custom_sequence] + +if cli.config[:destroy_vm] + puts "Unregistering and deleting VM #{vm_name}" + Instalatron.destroy_vm(vm_name) +end