require "optparse" require "rubygems/text" module Ahnnotate class Cli def initialize(name:) @name = name @options = Options.new(fix: false) end def run(argv, config = nil) argv = argv.dup debug_options = argv.delete("--debug-opts") || argv.delete("--debug-options") parser.parse(argv) if debug_options puts @options end if @options.exit? return end root = Pathname.new(Dir.pwd) config ||= Config.load(root: root) Function::Main.new(root, @options, config).call end private def parser if instance_variable_defined?(:@parser) return @parser end @parser = OptionParser.new do |opts| opts.banner = "Usage: #{@name} [options]" opts.separator "" opts.separator "Command line options:" opts.separator "" opts.on("--[no-]fix", "Actually modify files") do |fix| @options.fix = fix end opts.on("-h", "--help", "Prints this help message") do @options.exit = true puts opts end opts.on("--version", "Print version") do @options.exit = true puts Ahnnotate::VERSION end opts.separator "" opts.separator "" opts.separator "Configuration file:" opts.separator "" # The gsub converts all non-consecutive newlines into a space. # Consecutive newlines are left alone. configuration_file_help = <<-MSG.gsub(/(?