#!/usr/bin/ruby
# -*- coding: utf-8 -*-
require "capillary/log_parser"

parser = Capillary::LogParser.new

if ARGV == ["-v"] || ARGV == ["--version"]
  require "capillary/version"
  puts "Capillary #{Capillary::VERSION}"
elsif ARGV == ["-h"] || ARGV == ["--help"]
  puts "Convert git log on STDIN to JSON suitable for further processing by capillary.js"
  puts ""
  puts "Generate suitable log output from Git like this: (where --all is optional)"
  puts "git log --pretty=format:\"%H§%P§%ad§%ae§%d§%s§\" --decorate=full --graph --all"
  puts ""
  puts "Generate ASCII graph if you have installed capillary.js:"
  puts "git log --pretty=format:\"%H§%P§%ad§%ae§%d§%s§\" --decorate=full --graph --all | capillary | capillary-js"
else
  $stdin.each { |line| parser << line }
  puts parser.to_json
end
