lib/geordi/commands/setup_vnc.rb in geordi-1.0.2 vs lib/geordi/commands/setup_vnc.rb in geordi-1.0.3

- old
+ new

@@ -1,84 +1,66 @@ -class ::String - def colorize(color_code) - "\e[#{color_code}m#{self}\e[0m" - end - - def red() colorize(31) end - def pink() colorize(35) end - def green() colorize(32) end -end - desc 'setup-vnc', 'Setup VNC for running Selenium tests there' def setup_vnc `clear` - instruct <<-TEXT - This script will help you install a VNC server and a VNC viewer. - + note 'This script will help you install a VNC server and a VNC viewer.' + puts + puts strip_heredoc <<-TEXT With those you will be able to use our cucumber script without being - disturbed by focus-stealing selenium windows. Instead, they will open - inside a VNC session. You can still inspect everything with #{"geordi - vnc_show".pink}. + disturbed by focus-stealing Selenium windows. Instead, they will open + inside a VNC session. - Please open a second shell to execute instructions. + You can still inspect everything with: TEXT + note_cmd 'geordi vnc-show' + puts + note 'Please open a second shell to execute instructions.' + prompt 'Continue ...' announce 'Setup VNC server' - if installed?('vncserver') + vnc_server_installed = system('which vncserver > /dev/null 2>&1') + if vnc_server_installed success 'It appears you already have a VNC server installed. Good job!' else - instruct <<-TEXT - Please run #{'sudo apt-get install vnc4server'.pink}. - TEXT + puts 'Please run:' + note_cmd 'sudo apt-get install vnc4server' + prompt 'Continue ...' - instruct <<-TEXT - We will now set a password for your VNC server. - + puts + note 'We will now set a password for your VNC server.' + puts strip_heredoc <<-TEXT When running our cucumber script, you will not actually need this password, and there is no security risk. However, if you start a vncserver without our cucumber script, a user with your password can connect to your machine. - Please run #{'vncserver :20'.pink} and #{'enter a secure password'.red}. TEXT + puts 'Please run:' + note_cmd 'vncserver :20' + warn 'Enter a secure password!' + prompt 'Continue ...' - instruct <<-TEXT - Now stop the server again. - Please run #{'vncserver -kill :20'.pink}. - TEXT + puts 'Now stop the server again. Please run:' + note_cmd 'vncserver -kill :20' + prompt 'Continue ...' end announce 'Setup VNC viewer' - if installed?('vncviewer') + vnc_viewer_installed = system('which vncviewer > /dev/null 2>&1') + if vnc_viewer_installed success 'It appears you already have a VNC viewer installed. Good job!' else - instruct <<-TEXT - Please run #{'sudo apt-get install xtightvncviewer'.pink}. - TEXT + puts 'Please run:' + note_cmd 'sudo apt-get install xtightvncviewer' + prompt 'Continue ...' end - instruct <<-TEXT, false + puts + puts strip_heredoc <<-TEXT All done. Our cucumber script will now automatically run Selenium features in VNC. - #{"Happy cuking!".green} TEXT -end - -private - -def instruct(text, wait = true) - text =~ /^( *)./ - level = $1 ? $1.size : 0 - text.gsub!(/^ {#{level}}/, '') - puts text - - wait('[ENTER]') if wait -end - -def installed?(app) - `which #{app}` - $?.success? + success 'Happy cuking!' end