#!/usr/bin/env ruby begin require 'depl' rescue LoadError require 'rubygems' require 'depl' end require 'optparse' require 'highline/import' require 'colorize' options = {} options[:environment] = ARGV.shift options[:rev] = ENV['REV'] optparse = OptionParser.new do |opts| opts.banner = "Usage: depl [environment] [options]" opts.on("-c", "--config=CONFIG", String, "Location of .deploy configuration file") do |c| options[:config_file] = c end opts.on("-r", "--revision=REVISION", String, "Revision to deploy (can be sha, branch, etc)") do |r| options[:rev] = r end end optparse.parse! unless options[:environment] puts "Error: environment required" puts optparse exit 1 end deploy = Depl::Main.new(options) if deploy.up_to_date puts "Everything up-to-date (#{deploy.environment.green}: #{deploy.remote_sha.green})" exit 0 end if deploy.remote_sha.nil? puts "New deployment: #{deploy.local_sha}" else puts "Attempting to deploy #{deploy.local_sha.bold}", "" commits = "#{deploy.commit_count} new commit(s)".green puts "Difference of #{commits} between #{deploy.remote_sha} and #{deploy.local_sha}:", "" if deploy.commit_count > 0 puts deploy.diff.yellow, "" else puts " There are no new commits.", "" end end if deploy.older_local_sha puts "WARNING: The commit you are deploying is older than what is currently on #{deploy.environment}. Missing commits: ".bold, "" puts deploy.reverse_diff.red puts "" end confirm = ask("Deploy #{deploy.environment}? ([y]es / [n]o / [g]ithub) : ") { |yn| yn.limit = 1, yn.validate = /([yng]|yes|no|github)/i } case confirm.downcase when 'y', 'yes' deploy.run! puts "Deployed #{deploy.remote_sha}" when 'g', 'github' url = Depl::Remote.comparison(deploy.remote_sha, deploy.local_sha) if url if `which open`.size > 0 `open #{url}` else puts " Github: #{url}" end else puts "Unrecognized repository; can't open github" puts "(try `git config --get remote.origin.url`)" exit 1 end when 'n', 'no' puts "Bye." end