#!/usr/bin/env ruby require 'method_log' require 'optimist' options = Optimist::options do version MethodLog::VERSION banner <<-EOS Display the commit history for a single method. Usage: method_log [options] where is in the Ruby Index format e.g. Foo#bar, Bar::Baz#foo, Baz.foo. and [options] are: EOS opt :patch, 'Generate patch.' opt :ruby_version, 'Parser Ruby version (e.g. 2.5)', default: 'current' opt :max_count, 'Limit the number of commits to output.', type: :integer, short: 'n' opt :stop_at_latest_introduction_of_method, 'Stop at lastest introduction of method.', default: true opt :repository_path, 'Path to repository', default: Dir.pwd end Optimist.die 'No method signature specified' if ARGV.empty? method_signature = ARGV[0] case ruby_version = options[:ruby_version] when 'current' require 'parser/current' when /^(\d)\.(\d)$/ begin require "parser/ruby#{$1}#{$2}" Parser::CurrentRuby = Parser.const_get("Ruby#{$1}#{$2}") rescue LoadError Optimist.die "Ruby version not supported: #{ruby_version}" end else Optimist.die "Ruby version not supported: #{ruby_version}" end require 'method_log/repository' require 'method_log/api' repository = MethodLog::Repository.new(options[:repository_path]) api = MethodLog::API.new(repository) api.diffs(method_signature, options).each do |method_commit, method_diff| puts method_commit.to_s puts if options[:patch] puts method_diff.to_s(:color) puts end end