#!/usr/bin/env ruby require 'repo_manager' require 'optparse' require 'term/ansicolor' require 'fileutils' available_actions = RepoManager::AVAILABLE_ACTIONS banner = < e puts "repo #{e}" puts "repo --help for more information" exit 1 end # OptionParser is too helpful and matches short options with long. Before the # second pass, replace short git options with long because we can't tell # OptionParser to stop matching short options to long. ARGV.each_with_index do |arg, index| # check and replace each short git option # that could be parsed by main parser case arg when '-m' ARGV[index] = '--message' end end # second pass find all global options that may come after the action/subcommand # and its args, no errors raised, validity will be checked by action parser argv = [] while unknown_arg = ARGV.shift argv << unknown_arg begin optparser.order! rescue OptionParser::InvalidOption => e # put unknown args back on ARGV e.recover(ARGV) end end # settings from config file, if it exists, will not overwrite command line options settings = RepoManager::Settings.new(FileUtils.pwd, options) color = settings.options[:color] # add summary of general options for use by action help commands configuration = settings.to_hash if STDOUT.isatty || (color == 'ALWAYS') Term::ANSIColor::coloring = color if color && RepoManager::WINDOWS unless ENV['ANSICON'] begin require 'Win32/Console/ANSI' rescue LoadError Term::ANSIColor::coloring = false STDERR.puts 'WARNING: You must "gem install win32console" (1.2.0 or higher) or use the ANSICON driver (https://github.com/adoxa/ansicon) to get color output on MRI/Windows' end end end else Term::ANSIColor::coloring = false end app = RepoManager::App.new(argv, configuration) app.option_parser = optparser app.execute