Class: Testbot::CLI
- Inherits:
-
Object
- Object
- Testbot::CLI
- Defined in:
- lib/shared/testbot.rb
Class Method Summary collapse
- .lib_path ⇒ Object
- .parse_args(argv) ⇒ Object
- .run(argv) ⇒ Object
- .start_requester(opts, adapter) ⇒ Object
- .start_runner(opts) ⇒ Object
- .start_server(type) ⇒ Object
- .stop(name, pid) ⇒ Object
- .valid_runner_opts?(opts) ⇒ Boolean
Class Method Details
.lib_path ⇒ Object
126 127 128 |
# File 'lib/shared/testbot.rb', line 126 def self.lib_path File.(File.join(File.dirname(__FILE__), '..', 'lib')) end |
.parse_args(argv) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/shared/testbot.rb', line 52 def self.parse_args(argv) last_setter = nil hash = {} str = '' argv.each_with_index do |arg, i| if arg.include?('--') str = '' last_setter = arg.split('--').last.to_sym hash[last_setter] = true if (i == argv.size - 1) || argv[i+1].include?('--') else str += ' ' + arg hash[last_setter] = str.strip end end hash end |
.run(argv) ⇒ Object
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 |
# File 'lib/shared/testbot.rb', line 26 def self.run(argv) return false if argv == [] opts = parse_args(argv) if opts[:help] return false elsif opts[:version] puts "Testbot #{Testbot.version}" elsif [ true, 'run', 'start' ].include?(opts[:server]) start_server(opts[:server]) elsif opts[:server] == 'stop' stop('server', Testbot::SERVER_PID) elsif [ true, 'run', 'start' ].include?(opts[:runner]) require File.(File.join(File.dirname(__FILE__), '/../runner/runner')) return false unless valid_runner_opts?(opts) start_runner(opts) elsif opts[:runner] == 'stop' stop('runner', Testbot::RUNNER_PID) elsif adapter = Adapter.all.find { |adapter| opts[adapter.type.to_sym] } require File.(File.join(File.dirname(__FILE__), '/../requester/requester')) start_requester(opts, adapter) end true end |
.start_requester(opts, adapter) ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/shared/testbot.rb', line 112 def self.start_requester(opts, adapter) requester = Requester::Requester.new(:server_host => opts[:connect], :rsync_path => opts[:rsync_path], :rsync_ignores => opts[:rsync_ignores].to_s, :available_runner_usage => nil, :project => opts[:project], :ssh_tunnel => opts[:ssh_tunnel], :server_user => opts[:user]) requester.run_tests(adapter, adapter.base_path) end |
.start_runner(opts) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/shared/testbot.rb', line 69 def self.start_runner(opts) stop('runner', Testbot::RUNNER_PID) proc = lambda { working_dir = opts[:working_dir] || Testbot::DEFAULT_WORKING_DIR FileUtils.mkdir_p(working_dir) Dir.chdir(working_dir) runner = Runner::Runner.new(:server_host => opts[:connect], :auto_update => opts[:auto_update], :max_instances => opts[:cpus], :ssh_tunnel => opts[:ssh_tunnel], :server_user => opts[:user], :max_jruby_instances => opts[:max_jruby_instances], :dev_gem_root => opts[:dev_gem_root], :wait_for_updated_gem => opts[:wait_for_updated_gem], :jruby_opts => opts[:jruby_opts]) runner.run! } if opts[:runner] == 'run' proc.call else puts "Testbot runner started (pid: #{Process.pid})" SimpleDaemonize.start(proc, Testbot::RUNNER_PID, "testbot (runner)") end end |
.start_server(type) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/shared/testbot.rb', line 94 def self.start_server(type) stop('server', Testbot::SERVER_PID) require File.(File.join(File.dirname(__FILE__), '/../server/server')) if type == 'run' Sinatra::Application.run! :environment => "production" else puts "Testbot server started (pid: #{Process.pid})" SimpleDaemonize.start(lambda { Sinatra::Application.run! :environment => "production" }, Testbot::SERVER_PID, "testbot (server)") end end |
.stop(name, pid) ⇒ Object
108 109 110 |
# File 'lib/shared/testbot.rb', line 108 def self.stop(name, pid) puts "Testbot #{name} stopped" if SimpleDaemonize.stop(pid) end |
.valid_runner_opts?(opts) ⇒ Boolean
122 123 124 |
# File 'lib/shared/testbot.rb', line 122 def self.valid_runner_opts?(opts) opts[:connect].is_a?(String) end |