Permalink
Browse files

Modified the cli to base on thor gem.

  • Loading branch information...
1 parent 997e276 commit 49c6d54355c86177a5feed8f4ec50e0602cb6a05 @dbck dbck committed Aug 15, 2013
Showing with 12 additions and 22 deletions.
  1. +1 −2 bin/git_stats
  2. +11 −20 lib/git_stats/cli.rb
View
@@ -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)
View
@@ -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

0 comments on commit 49c6d54

Please sign in to comment.