From 49c6d54355c86177a5feed8f4ec50e0602cb6a05 Mon Sep 17 00:00:00 2001 From: Dennis Boeckmann Date: Thu, 15 Aug 2013 22:02:25 +0200 Subject: [PATCH] Modified the cli to base on thor gem. --- bin/git_stats | 3 +-- lib/git_stats/cli.rb | 31 +++++++++++-------------------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/bin/git_stats b/bin/git_stats index aea13ad69..6d740ee5d 100755 --- a/bin/git_stats +++ b/bin/git_stats @@ -7,5 +7,4 @@ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib) # start up the CLI require "git_stats/cli" -cli = GitStats::CLI.new -cli.start +GitStats::CLI.start(ARGV) diff --git a/lib/git_stats/cli.rb b/lib/git_stats/cli.rb index 90a5aa2cc..7a0941516 100644 --- a/lib/git_stats/cli.rb +++ b/lib/git_stats/cli.rb @@ -1,27 +1,18 @@ # -*- encoding : utf-8 -*- require "git_stats" -require "highline/import" +require "thor" -class GitStats::CLI +class GitStats::CLI < Thor + option :path, :aliases => :p, :default => '.', :desc => 'Path to repository from which statistics should be generated.' + option :output, :aliases => :o, :default => './git_stats', :desc => 'Output path where statistics should be written.' + option :language, :aliases => :l, :default => 'en', :desc => 'Language of written statistics.' + option :from, :aliases => :f, :desc => 'Commit from where statistics should start.' + option :to, :aliases => :t, :default => 'HEAD', :desc => 'Commit where statistics should stop.' - def start - - repo_path = ask("Repo path? ") { |q| - q.default = "." - q.validate = lambda { |p| GitStats::Validator.new.valid_repo_path?(p) } - q.responses[:not_valid] = "Given path is not a git repository, try again" - } - - out_path = ask("Output dir? ") { |q| q.default = "./git_stats" } - I18n.locale = ask("Language? ") { |q| q.default = "en"; q.answer_type = Symbol } - specify_range = agree("Want to specify commits range? ") { |q| q.default = "no" } - - if specify_range - first_commit_sha = ask("Starting commit sha? ") { |q| q.default = nil } - last_commit_sha = ask("Ending commit sha? ") { |q| q.default = "HEAD" } - end - - GitStats::Generator.new(repo_path, out_path, first_commit_sha, last_commit_sha) { |g| + desc 'generate', 'Generates the statistics of a repository' + def generate + I18n.locale = options[:language] + GitStats::Generator.new(options[:path], options[:output], options[:from], options[:to]) { |g| g.add_command_observer { |command, result| puts "#{command}" } }.render_all end