#!/usr/bin/env ruby $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), *%w(.. lib))) require "optparse" require "caravan" options = {} option_parser = OptionParser.new do |opts| opts.banner = "Caravan #{Caravan::VERSION}\nCopyright (c) David Zhang 2017\n" opts.separator "" opts.on("-s SOURCE_PATH", "--source SOURCE_PATH", "Source path") do |value| options[:src] = value end opts.on("-d DEST_PATH", "--dest DEST_PATH", "Destination path") do |value| options[:dst] = value end opts.on("-m DEPLOY_MODE", "--mode DEPLOY_MODE", "Deploy mode") do |value| options[:mode] = value || "shell" end opts.on("-i IGNORE_FILES", "--ignore IGNORE_FILES", "Ignore files") do |value| if options.key?(:ignore) options[:ignore] << value else options[:ignore] = [value] end end options[:debug] = false opts.on("-b", "--debug", "Debug mode") do options[:debug] = true end opts.on_tail("--version", "Show version") do puts Caravan::VERSION exit end end if ARGV.size == 1 && ARGV[0] == "init" Caravan.dump_default_conf end option_parser.parse!(ARGV) merged_conf = Caravan::Config.merge(options, Caravan.process_conf(options[:src])) if merged_conf.key?('src') && merged_conf.key?('dst') && merged_conf.key?('deploy_mode') Caravan.start(merged_conf) else Caravan::Message.error('No src, dst, deploy_mode specified. Cannot deploy.') end