Add commit range to the CLI

This adds 4th and 5th optional CLI parameters that specifies the first
and last SHA commit to generate stats between.
The generator and repo classes were changed to take these as
initialisation parameters.
It would be nice to have the CLI take individual named optional
parameters, so that only first or last commit could be given and
without having to give the language.
This commit is contained in:
Nick Brown 2013-04-03 12:35:12 +01:00
parent 42f7240643
commit 8f67bcdc64
4 changed files with 8 additions and 8 deletions

View file

@ -20,12 +20,12 @@ It browses the repository and outputs html page with statistics.
### Generator ### Generator
$ git_stats repo_path output_directory $ git_stats repo_path output_directory language_code first_commit_sha last_commit_sha
$ favorite_browser output_directory/index.html $ favorite_browser output_directory/index.html
### API usage example ### API usage example
> repo = GitStats::GitData::Repo.new(path: '.') > repo = GitStats::GitData::Repo.new(path: '.', first_commit_sha: 'abcd1234', last_commit_sha: 'HEAD')
> repo.authors > repo.authors
=> [...] => [...]
> repo.commits > repo.commits

View file

@ -4,12 +4,12 @@ require "git_stats"
class GitStats::CLI class GitStats::CLI
def start(*args) def start(*args)
raise "Wrong number of arguments\nUsage: git_stats repo_path output_path <output_lang>" unless [2, 3].include? args.size raise "Wrong number of arguments\nUsage: git_stats repo_path output_path <output_lang>" unless [2, 3, 4, 5].include? args.size
repo_path, out_path, lang = args repo_path, out_path, lang, first_commit_sha, last_commit_sha = args
I18n.locale = lang || :en I18n.locale = lang || :en
GitStats::Generator.new(repo_path, out_path) { |g| GitStats::Generator.new(repo_path, out_path, first_commit_sha, last_commit_sha) { |g|
g.add_command_observer { |command, result| puts "#{command}" } g.add_command_observer { |command, result| puts "#{command}" }
}.render_all }.render_all
end end

View file

@ -4,10 +4,10 @@ module GitStats
delegate :add_command_observer, to: :@repo delegate :add_command_observer, to: :@repo
delegate :render_all, to: :@view delegate :render_all, to: :@view
def initialize(repo_path, out_path) def initialize(repo_path, out_path, first_commit_sha, last_commit_sha)
validate_repo_path(repo_path) validate_repo_path(repo_path)
@repo = GitData::Repo.new(path: repo_path) @repo = GitData::Repo.new(path: repo_path, first_commit_sha: first_commit_sha, last_commit_sha: last_commit_sha)
view_data = StatsView::ViewData.new(@repo) view_data = StatsView::ViewData.new(@repo)
@view = StatsView::View.new(view_data, out_path) @view = StatsView::View.new(view_data, out_path)

View file

@ -6,7 +6,7 @@ module GitStats
class Repo class Repo
include HashInitializable include HashInitializable
attr_reader :path attr_reader :path, :first_commit_sha, :last_commit_sha
delegate :files, :files_by_extension, :files_by_extension_count, :lines_by_extension, delegate :files, :files_by_extension, :files_by_extension_count, :lines_by_extension,
:files_count, :binary_files, :text_files, :lines_count, to: :last_commit :files_count, :binary_files, :text_files, :lines_count, to: :last_commit