bin/buildbox in buildbox-0.0.4 vs bin/buildbox in buildbox-0.1
- old
+ new
@@ -1,99 +1,7 @@
#!/usr/bin/env ruby
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir)
-require 'buildbox'
-require 'optparse'
-commands = {}
-options = {}
-
-help = <<HELP
-
- auth # authentication (login, logout)
- monitor # monitor builds (start, stop)
- version # display version
-
-HELP
-
-global = OptionParser.new do |opts|
- opts.version = Buildbox::VERSION
- opts.banner = 'Usage: buildbox COMMAND [command-specific-actions]'
-
- opts.separator help
-end
-
-commands['auth:login'] = OptionParser.new do |opts|
- opts.banner = "Usage: buildbox auth:login API_KEY"
-end
-
-commands['auth:logout'] = OptionParser.new do |opts|
- opts.banner = "Usage: buildbox auth:logout"
-end
-
-commands['monitor:start'] = OptionParser.new do |opts|
- opts.banner = "Usage: buildbox monitor:start"
-
- opts.on("-d", "--daemon", "Runs as a daemon") do
- options[:daemon] = true
- end
-
- opts.on("--help", "You're looking at it.") do
- puts commands['monitor:start']
- exit
- end
-end
-
-commands['monitor:stop'] = OptionParser.new do |opts|
- opts.banner = "Usage: buildbox monitor:stop"
-end
-
-commands['version'] = OptionParser.new do |opts|
- opts.banner = "Usage: buildbox version"
-end
-
-global.order!
-
-args = ARGV
-
-if command = args.shift
- if commands.has_key?(command)
- commands[command].parse!
- else
- puts "`#{command}` is an unknown command"
- exit 1
- end
-
- if command == "version"
- puts Buildbox::VERSION
- exit
- end
-
- if command =~ /^monitor/
- client = Buildbox::Client.new(options)
- if command == "monitor:start"
- client.start
- elsif command == "monitor:stop"
- client.stop
- end
- end
-
- if command =~ /^auth/
- auth = Buildbox::Auth.new
-
- if command == "auth:login"
- api_key = args[0]
-
- unless api_key
- puts commands['auth:login']
- exit
- end
-
- auth.login(:api_key => args[0])
- elsif command == "auth:logout"
- auth.logout
- end
- end
-else
- puts global.help
-end
+require 'buildbox'
+Buildbox::CLI.new(ARGV).parse