Sha256: 4168a4f7a8051f98f9438a78b4ed38cf23d100e983a7ea2f1124cb9a739d06ad

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

#!/usr/bin/env ruby

require 'githubchart'
require 'optparse'

options = {}
OptionParser.new do |opts|
  opts.banner =
    "Usage: githubchart (-u username) (-t type) path/for/new/image\n"
  opts.banner << 'Supported types: ' + GithubChart.supported.join(' ')
  opts.on('-uUSER', '--user=USER', 'Specify GitHub user to graph') do |user|
    if options.include? :input
      fail 'The --user and --input flags are incompatible with each other.'
    end
    options[:user] = user
  end
  opts.on('-iFILE', '--input=FILE', 'Specify JSON file, - for stdin') do |input|
    if options.include? :user
      fail 'The --user and --input flags are incompatible with each other.'
    end

    if input.eql? '-'
      fail 'No data provided on stdin' if STDIN.tty?
      contents = STDIN.read
    else
      fail 'File does not exist' unless File.exist? input
      contents = File.read input
    end

    begin
      parsed = JSON.parse(contents)
    rescue => e
      raise "Unable to parse JSON data provided: #{e}"
    end

    options[:data] = GithubStats::Data.new(parsed)
  end
  opts.on_tail('-v', '--version', 'Show version') do
    puts GithubChart::VERSION
    exit
  end
end.parse!

SVG_Path = ARGV.shift
fail 'Please provide the target location for the SVG' if SVG_Path.nil?

Chart = GithubChart.new(options).svg

File.open(SVG_Path, 'w') { |file| file << Chart }

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
githubchart-0.0.8 bin/githubchart