#!/usr/bin/env 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 " plugin list - list all local assertion plugins" opts.separator " plugin generate - generate a template for a local plugin" 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"] YSI::Init.new(Dir.pwd).setup_config elsif ARGV[0] == "plugin" plugin = YSI::Plugin.new(Dir.pwd) if ARGV[1] == "list" plugin.list elsif ARGV[1] == "generate" if !ARGV[2].is_a?(String) && !ARGV[3].is_a?(String) STDERR.puts "Parameters are missing. Use for example" STDERR.puts STDERR.puts " yes_ship_it plugin generate my_plugin \"My plugin\"" STDERR.puts STDERR.puts "to generate a plugin `my_plugin` with a display name of \"My plugin\"." exit 1 end plugin.generate(ARGV[2], ARGV[3]) else STDERR.puts "Invalid command" STDERR.puts STDERR.puts option_parser exit 1 end 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 YSI::Plugin.new(Dir.pwd).load 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