diff options
author | Daniel DeLeo <dan@opscode.com> | 2011-02-03 23:47:41 -0800 |
---|---|---|
committer | Daniel DeLeo <dan@opscode.com> | 2011-02-03 23:47:41 -0800 |
commit | 514c51cf35ccddb6accf8f5a60174649187b521c (patch) | |
tree | c9753462c815fe616d277e27f19a0f09006fa03e /scripts | |
parent | 5b59c478edda1491362d2de560758c3c95bd79eb (diff) | |
download | chef-514c51cf35ccddb6accf8f5a60174649187b521c.tar.gz |
update features infrastructure for chef-expander
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/mac-dev-start | 107 |
1 files changed, 63 insertions, 44 deletions
diff --git a/scripts/mac-dev-start b/scripts/mac-dev-start index 78faf962d6..b2b029335a 100755 --- a/scripts/mac-dev-start +++ b/scripts/mac-dev-start @@ -1,59 +1,78 @@ #!/usr/bin/env ruby require 'rubygems' +require 'pp' require 'appscript' +require 'mixlib/cli' -include Appscript - -SRCDIR = File.expand_path(File.join(File.dirname(__FILE__), "..")) -DELAY = 1 -BASE_CMD = case ARGV[0] - when "features" - "cd #{SRCDIR} && rake dev:features:start:" - when "dev" - "cd #{SRCDIR} && rake dev:start:" - else - "cd #{SRCDIR} && rake dev:start:" - end -SERVICES = ["couchdb","rabbitmq","chef_solr","chef_solr_indexer","chef_server","chef_webui"] - -def auth_up - #system("sudo echo") -end +class MacDevStart + include Mixlib::CLI + include Appscript -def create_tab - app("System Events").application_processes["Terminal.app"].keystroke("t", :using=>:command_down) -end + SERVICES = %w{couchdb rabbitmq chef_solr chef_expander chef_server chef_webui} -def activate_terminal - app("/Applications/Utilities/Terminal.app").windows.first.activate - app("System Events").application_processes["Terminal.app"].keystroke("n", :using=>:command_down) - app('Terminal') -end + option :environment, + :short => '-e ENV', + :long => '--environment ENV', + :default => 'test', + :description => 'Set the environment (test|dev), defaults to test' -def start_service_in_last_tab(window,service) - # use xterm escape codes to set the tab title to the service running in the tab. - cmd = - "unset PROMPT_COMMAND; echo -e \"\\033]0;#{service}\\007\"; " + - BASE_CMD + - service + def run + @srcdir = File.expand_path(File.dirname(__FILE__)) - app('Terminal').do_script(cmd, :in => window.tabs.last.get) - sleep DELAY -end + @base_cmd = case config[:environment] + when 'test' + "cd #{@srcdir} && rake dev:features:start:" + when 'dev' + "cd #{@srcdir} && rake dev:start:" + else + puts "--environment must be set to either 'test' or 'dev'" + puts @opt_parser + exit 1 + end + + STDOUT.puts "Starting services:" + pp SERVICES + start_services(SERVICES) + end + + def create_tab + @window.activate + app("System Events").application_processes["Terminal.app"].keystroke("t", :using=>:command_down) + end + + def terminal_app + @terminal_app ||= app("Terminal") + end + + def create_term_window + terminal_app.windows.first.activate + app("System Events").application_processes["Terminal.app"].keystroke("n", :using=>:command_down) + @window = terminal_app.windows.first.get + end -def start_services - auth_up - term = activate_terminal - window = term.windows.first.get - - SERVICES.each do |service| - create_tab - start_service_in_last_tab(window,service) + def start_service_in_tab(service, tab) + # use xterm escape codes to set the tab title to the service running in the tab. + cmd = "unset PROMPT_COMMAND; echo -e \"\\033]0;#{service}\\007\"; #{@base_cmd}#{service}" + app('Terminal').do_script(cmd, :in => @window.tabs[tab].get) + end + + def start_services(services) + create_term_window + + tab_index = 1 # applescript indexes from 1 instead of 0 + + (services.size - 1).times { create_tab } + + services.each do |service| + start_service_in_tab(service, tab_index) + tab_index += 1 + end end end if __FILE__ == $0 - start_services + os = MacDevStart.new + os.parse_options + os.run end - |