#!/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 2018\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[:once] = false opts.on("-o", "--once", "Deploy for once") do options[:once] = true end options[:debug] = false opts.on("-b", "--debug", "Debug mode") do options[:debug] = true end opts.on_head("--init", "Init caravan.yml") do Caravan.dump_default_conf Caravan::Message.success("Generated #{Caravan::Config.default_conf_name}") exit end opts.on_tail("--version", "Show version") do puts Caravan::VERSION exit end end if ARGV.length == 0 merged_conf = Caravan::Config.merge({}, Caravan.process_conf(".")) else option_parser.parse!(ARGV) merged_conf = Caravan::Config.merge(options, Caravan.process_conf(options[:src])) end 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