bin/method_log in method_log-0.1.1 vs bin/method_log in method_log-0.2.0

- old
+ new

@@ -1,41 +1,52 @@ #!/usr/bin/env ruby require 'method_log' -require 'trollop' +require 'optimist' -options = Trollop::options do - opt :patch, 'Generate patch.', short: 'p' - opt :ruby_version, 'Parser Ruby version (18, 19, 20, 21)', default: 'current' +options = Optimist::options do + version MethodLog::VERSION + banner <<-EOS +Display the commit history for a single method. + +Usage: + method_log [options] <method-signature> + +where <method-signature> 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 '18', '19', '20', '21' - require 'parser/ruby18' - require 'parser/ruby19' - require 'parser/ruby20' - require 'parser/ruby21' - Parser::CurrentRuby = Parser.const_get("Ruby#{ruby_version}") +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 - raise "Ruby version not supported: #{ruby_version}" + Optimist.die "Ruby version not supported: #{ruby_version}" end -require 'method_log' require 'method_log/repository' require 'method_log/api' -repository = MethodLog::Repository.new(Dir.pwd) +repository = MethodLog::Repository.new(options[:repository_path]) api = MethodLog::API.new(repository) -api.diffs(ARGV[0], options).each do |method_commit, method_diff| - puts "commit #{method_commit.sha}" - puts "Author: #{method_commit.author[:name]} <#{method_commit.author[:email]}>" - puts "Date: #{method_commit.author[:time].strftime('%a %b %-e %T %Y %z')}" - puts - puts method_commit.message +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