lib/buildbox/cli.rb in buildbox-0.2 vs lib/buildbox/cli.rb in buildbox-0.2.1

- old
+ new

@@ -7,24 +7,33 @@ def initialize(argv) @argv = argv @commands = {} @options = {} + @commands['auth:login'] = OptionParser.new do |opts| + opts.banner = "Usage: buildbox auth:login" + + opts.on("--help", "You're looking at it.") do + puts @commands['auth:login'] + exit + end + end + @commands['worker:start'] = OptionParser.new do |opts| opts.banner = "Usage: buildbox worker:start" opts.on("--help", "You're looking at it.") do puts @commands['worker:start'] exit end end - @commands['worker:setup'] = OptionParser.new do |opts| - opts.banner = "Usage: buildbox worker:setup [token]" + @commands['worker:add'] = OptionParser.new do |opts| + opts.banner = "Usage: buildbox worker:add [token]" opts.on("--help", "You're looking at it.") do - puts @commands['worker:setup'] + puts @commands['worker:add'] exit end end @commands['version'] = OptionParser.new do |opts| @@ -50,21 +59,39 @@ exit end if command == "worker:start" Buildbox::Server.new.start - elsif command == "worker:setup" + elsif command == "worker:add" if @argv.length == 0 puts "No token provided" exit 1 end access_token = @argv.first worker_access_tokens = Buildbox.config.worker_access_tokens Buildbox.config.update(:worker_access_tokens => worker_access_tokens << access_token) puts "Successfully added worker access token" - puts "You can now start the worker with `buildbox worker:start`" + puts "You can now start the worker with: buildbox worker:start" + elsif command == "auth:login" + if @argv.length == 0 + puts "No api key provided" + exit 1 + end + + api_key = @argv.first + + begin + Buildbox::API.new.authenticate(api_key) + Buildbox.config.update(:api_key => api_key) + + puts "Successfully added your api_key" + puts "You can now add workers with: buildbox worker:add [worker_token]" + rescue + puts "Could not authenticate your api_key" + exit 1 + end end else puts global.help end end