Sha256: 987bc2fd073de5a45b3b151cde35b2a47d7adeed796c20dec9d8ce6002d193d0

Contents?: true

Size: 1.91 KB

Versions: 2

Compression:

Stored size: 1.91 KB

Contents

#! /usr/bin/env ruby
# resolve bin path, ignoring symlinks
require "pathname"
bin_file = Pathname.new(__FILE__).realpath

# add self to libpath
puts File.expand_path("../../lib", bin_file)
$:.unshift File.expand_path("../../lib", bin_file)

require 'churn/calculator'
require 'main'
require 'yaml'

#example usage. In the root of a project 'churn', or 'churn --help'
Main do
  option('minimum_churn_count', 'c') do
    argument :required
    cast :int
    default 3
  end

  option('yaml', 'y') do
    cast :boolean
    default false
  end

  option('ignore_files', 'i') do
    cast :string
    argument :optional
    default ''
  end

  option('report', 'r') do
    cast :string
    argument :optional
    default ''
  end

  option('name', 'n') do
    cast :string
    argument :optional
    default ''
    description 'name is require if remotely reporting churn results. If available as a github project, pass name in the form of username/project_name'
  end

  option('start_date', 's') do
    cast :string
    argument :optional
    default ''
  end

  option('data_directory', 'd') do
    cast :string
    argument :optional
    default ''
  end

  #grrr h is already taken by --help / -h so whent with 'p'
  option('past_history', 'p') do
    cast :string
    argument :optional
    default ''
  end

  def report_churn(output_string)
    options = {:minimum_churn_count => params['minimum_churn_count'].value,
      :ignore_files => params['ignore_files'].value,
      :start_date => params['start_date'].value,
      :data_directory => params['data_directory'].value,
      :history => params['past_history'].value,
      :report => params['report'].value,
      :name => params['name'].value
    }
    result = Churn::ChurnCalculator.new(options).report(output_string)
    unless output_string
      result = YAML::dump(result)
    end
    result
  end

  def run
    report = report_churn(!params['yaml'].value)
    puts report
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
churn-1.0.1 bin/churn
churn-0.0.35 bin/churn