#!/usr/bin/ruby require_relative("../lib/yes_ship_it.rb") options = {} option_parser = OptionParser.new do |opts| opts.banner = "Usage: yes_ship_it [options] [command]" opts.separator "" opts.separator "Commands:" opts.separator " changelog - show change log since last release" opts.separator " init - initialize directory for shipping with yes_ship_it" opts.separator "" opts.separator "Specific options:" opts.on("--dry-run", "Just pretend. Don't change anything.") do |v| options[:dry_run] = v end opts.on("--data-dir=DIR", "Set directory for storing internal data") do |v| options[:data_dir] = v end opts.on_tail("-h", "--help", "Show this message") do puts opts exit end end option_parser.parse! config_file = "yes_ship_it.conf" if ARGV == ["changelog"] engine = YSI::Engine.new engine.check_assertion(YSI::Version) tag = `git tag`.split("\n").last system("git log #{tag}..HEAD") exit 0 elsif ARGV == ["init"] File.open("yes_ship_it.conf", "w") do |file| file.puts "# Experimental release automation. See https://github.com/cornelius/yes_ship_it." file.puts "include:" file.puts " ruby_gem" end puts "Initialized directory for shipping." puts puts "Check the file `yes_ship_it.conf` and adapt it to your needs." puts puts "Happy shipping!" elsif ARGV.empty? if !File.exist?(config_file) STDERR.puts("Unable to find file `yes_ship_it.conf`. I need it.") exit 1 end puts "Shipping..." puts engine = YSI::Engine.new engine.dry_run = options[:dry_run] engine.data_dir = options[:data_dir] if options[:data_dir] begin engine.read(config_file) exit engine.run rescue YSI::Error => e STDERR.puts e exit 1 end else $stderr.puts "Unrecognized arguments: #{ARGV.join(" ")}" puts option_parser exit 1 end