Sha256: adf53b823024b9ab458eec654f57e4d65d889e7953d260c620b6a5c820e3bde8

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

#!/usr/bin/env ruby

require_relative '../lib/git_heat/git_stat'
require_relative '../lib/git_heat/git_client'
require_relative '../lib/git_heat/calculator'
require 'topchart'

class Object
  def pat(&blk)
    !self.nil? && blk.call(self)
  end
end


class Runner 
  def initialize(time)
    @time = time
  end

  def go(args,opts)
    args = Array(args)
    opts = Array(opts)
    dir = args[0] || Dir.pwd

    begin
      Calculator.new(@time).go(
        GitStat.new(
          GitClient.new(dir)
        ).stats
      ).map do |a|
        if opts.include? '--no-scores'
          a[0]
        else
          a[0].to_s.ljust(80) + a[1].to_s
        end
      end.to_a
    rescue Errno::EPIPE
    end
  end
end

opt = ->(a){ a[/^-/] }
opts = ARGV.select(&opt)
args = ARGV.reject(&opt)

time_opt = opts.detect{|o| o[/--time=(.*)/, 1] }.pat(&Time.method(:parse))
time = time_opt || Time.now
a_day = 60*60*24
chart_opt = opts.map{|o| o[/--chart(.*)$/, 1] }.compact.last.pat do |dur_str|
  dur_str = dur_str.gsub("=","")
  case dur_str
  when "day"
    a_day
  when "week"
    a_day*7
  when "30day"
    a_day*30
  else
    dur_str.to_i*a_day
  end
end
chart_duration = chart_opt || a_day

if chart_opt
  puts Topchart.new.chart(
    Runner.new(time-chart_duration).go(args, ["--no-scores"]),
    Runner.new(time).go(args, ["--no-scores"])
  ).map{|l| l.join(" ")}
else
  puts Runner.new(time).go(args, opts)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git_heat-0.2.0 bin/git-heat