Skip to content

Commit

Permalink
Refactor code and add a json option
Browse files Browse the repository at this point in the history
  • Loading branch information
etagwerker committed Mar 16, 2024
1 parent 33205b5 commit 2192345
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions bin/churn
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ bin_file = Pathname.new(__FILE__).realpath
$:.unshift File.expand_path("../../lib", bin_file)

require 'churn/calculator'
require 'churn/reporter'
require 'churn/version'
require 'main'
require 'yaml'
Expand All @@ -24,6 +25,11 @@ Main do
default false
end

option('json', 'j') do
cast :boolean
default false
end

option('ignore_files', 'i') do
cast :string
argument :optional
Expand Down Expand Up @@ -80,33 +86,9 @@ Main do
default false
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,
file_extension: params['extension'].value,
file_prefix: params['prefix'].value,
}
if params['version'].value
puts Churn::VERSION
return
end

result = Churn::ChurnCalculator.new(options).report(output_string)
if output_string
result
else
YAML::dump(result)
end
end

def run
report = report_churn(!params['yaml'].value)
reporter = Churn::ChurnReporter.new(params)
report = reporter.report_churn
puts report
end
end

0 comments on commit 2192345

Please sign in to comment.