#!/usr/bin/env ruby STDOUT.sync = true require 'trollop' opts = Trollop.options do version 'mgd 0.2.0' banner <<-EOS mgd is an automated deployer of Middleman site to Github Pages Usage: mgd [options] EOS opt :url, 'Github URL', type: String, default: '' opt :branch, 'Destination branch', type: String, default: 'gh-pages' end Trollop.die(:branch, 'can\'t be empty') if opts[:branch].empty? url = opts[:url] url = `git config --get remote.origin.url`.strip if url.empty? spec = Gem::Specification.find_by_name('mgd') root = spec.gem_dir script = File.join(root, 'bash/deploy.sh') Trollop.die('deployment failed, see log above') \ unless system("#{script} #{url} #{opts[:branch]}")