bin/sauce in sauce-1.0.2 vs bin/sauce in sauce-2.0.0

- old
+ new

@@ -8,81 +8,92 @@ require 'highline/import' sauce_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(sauce_dir) unless $LOAD_PATH.include?(sauce_dir) -# special case for sauce connect -if ARGV.length > 0 && ARGV[0] == 'connect' - require 'sauce/connect' - system ([Sauce::Connect.find_sauce_connect] + ARGV[1..100]).join(" ") -else require 'sauce' - cmd = CmdParse::CommandParser.new(true, true) - cmd.program_name = "sauce " - cmd.program_version = [0, 1, 0] +cmd = CmdParse::CommandParser.new(true, true) +cmd.program_name = "sauce " +cmd.program_version = [0, 1, 0] - cmd.add_command(CmdParse::HelpCommand.new) +cmd.add_command(CmdParse::HelpCommand.new) - # configure - class ConfigureCommand < CmdParse::Command - def usage - "Usage: #{commandparser.program_name}configure USERNAME ACCESS_KEY" - end +class ConnectCommand < CmdParse::Command + def usage + "Usage: #{commandparser.program_name}connect" end - configure = ConfigureCommand.new('configure', false) - configure.short_desc = "Configure Sauce OnDemand credentials" - configure.set_execution_block do |args| - if args.length < 2 - puts configure.usage - exit 1 - end - username = args[0] - access_key = args[1] - dir = File.join(File.expand_path("~"), ".sauce") - FileUtils.mkdir(dir) unless File.directory?(dir) +end +connect = ConnectCommand.new('connect', false) +connect.short_desc = 'Connect a Sauce Connect tunnel' +connect.set_execution_block do |args| + require 'sauce/connect' + require 'sauce/config' + config = Sauce::Config.new + command = "#{Sauce::Connect.connect_command} #{config.username} #{config.access_key} #{ARGV[1 .. -1]}" + exec(command) +end +cmd.add_command(connect) - out = File.new(File.join(dir, "ondemand.yml"), 'w') - out.write(YAML.dump({"username" => username, "access_key" => access_key})) - out.close() + +# configure +class ConfigureCommand < CmdParse::Command + def usage + "Usage: #{commandparser.program_name}configure USERNAME ACCESS_KEY" end - cmd.add_command(configure) +end +configure = ConfigureCommand.new('configure', false) +configure.short_desc = "Configure Sauce OnDemand credentials" +configure.set_execution_block do |args| + if args.length < 2 + puts configure.usage + exit 1 + end + username = args[0] + access_key = args[1] + dir = File.join(File.expand_path("~"), ".sauce") + FileUtils.mkdir(dir) unless File.directory?(dir) - #create - create = CmdParse::Command.new('create', false) - create.short_desc = "Create a new Sauce OnDemand account" - create.set_execution_block do |args| - puts "Let's create a new account!" - username = ask("Username: ") - password = ask("Password: ") { |q| q.echo = "*" } - email = ask("Email: ") - name = ask("Full name: ") + out = File.new(File.join(dir, "ondemand.yml"), 'w') + out.write(YAML.dump({"username" => username, "access_key" => access_key})) + out.close() +end +cmd.add_command(configure) - body = { - :username => username, - :password => password, - :email => email, - :name => name, - :token => "c8eb3e2645005bcbbce7e2c208c6b7a71555d908" - }.to_json +#create +create = CmdParse::Command.new('create', false) +create.short_desc = "Create a new Sauce OnDemand account" +create.set_execution_block do |args| + puts "Let's create a new account!" + username = ask("Username: ") + password = ask("Password: ") { |q| q.echo = "*" } + email = ask("Email: ") + name = ask("Full name: ") - begin - result = RestClient.post("http://saucelabs.com/rest/v1/users", - body, :content_type => :json, :accept => :json) - rescue => e - begin - puts "ERROR: #{JSON.load(e.response)['errors']}" - rescue - puts "ERROR: #{e.response}" - end - else - result = JSON.load(result) + body = { + :username => username, + :password => password, + :email => email, + :name => name, + :token => "c8eb3e2645005bcbbce7e2c208c6b7a71555d908" + }.to_json - puts "Account #{username} created successfully." - puts "Your access key is: #{result['access_key']}" + begin + result = RestClient.post("http://saucelabs.com/rest/v1/users", + body, :content_type => :json, :accept => :json) + rescue => e + begin + puts "ERROR: #{JSON.load(e.response)['errors']}" + rescue + puts "ERROR: #{e.response}" end + else + result = JSON.load(result) + + puts "Account #{username} created successfully." + puts "Your access key is: #{result['access_key']}" end +end - cmd.add_command(create) +cmd.add_command(create) - cmd.parse -end +cmd.parse