diff --git a/bin/gitstats b/bin/gitstats new file mode 100755 index 000000000..6aed849e5 --- /dev/null +++ b/bin/gitstats @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +# encoding: UTF-8 + +lib = File.expand_path(File.dirname(__FILE__) + '/../lib') +$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib) + +# start up the CLI +require "gitstats/cli" +GitStats::CLI.start(*ARGV) \ No newline at end of file diff --git a/gitstats.gemspec b/gitstats.gemspec index f6609f1b8..ae628b93a 100644 --- a/gitstats.gemspec +++ b/gitstats.gemspec @@ -10,10 +10,13 @@ Gem::Specification.new do |gem| gem.email = ["tomasz.gieniusz@gmail.com"] gem.description = %q{Git history statistics generator} gem.summary = %q{HTML statistics generator from git repository} - gem.homepage = "" + gem.homepage = "https://github.com/tomgi/gitstats" + gem.executables = "gitstats" gem.files = `git ls-files`.split($/) gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ["lib"] + + gem.add_development_dependency('pry') end diff --git a/lib/gitstats.rb b/lib/gitstats.rb index 179c205a4..4fd7529f2 100644 --- a/lib/gitstats.rb +++ b/lib/gitstats.rb @@ -1,5 +1,4 @@ -require "gitstats/version" - -module Gitstats - # Your code goes here... +module GitStats end + +Dir['lib/**/*.rb'].each { |r| require File.expand_path(r) } \ No newline at end of file diff --git a/lib/gitstats/cli.rb b/lib/gitstats/cli.rb new file mode 100644 index 000000000..df52e2f54 --- /dev/null +++ b/lib/gitstats/cli.rb @@ -0,0 +1,40 @@ +require "gitstats" + +class GitStats::CLI + + def self.start(*args) + unless args.size == 2 + puts "Wrong number of arguments" + help + else + repo_path, out_path = args + validate(repo_path, out_path) + GitStats::Generator.new(repo_path, out_path).generate + end + end + + private + def self.help + puts "Usage: gitstats repo_path output_path" + exit 0 + end + + def self.validate(repo_path, out_path) + validate_repo(repo_path) + validate_out(out_path) + end + + def self.validate_repo(repo_path) + unless Dir.exists?("#{repo_path}/.git") + puts "#{repo_path} is not a git repository" + help + end + end + + def self.validate_out(out_path) + unless Dir.exists?("#{out_path}") + puts "#{out_path} doesn't exist" + help + end + end +end diff --git a/lib/gitstats/generator.rb b/lib/gitstats/generator.rb new file mode 100644 index 000000000..91d1fcb22 --- /dev/null +++ b/lib/gitstats/generator.rb @@ -0,0 +1,9 @@ +class GitStats::Generator + def initialize(repo_path, out_path) + @repo_path, @out_path = repo_path, out_path + end + + def generate + puts "generating..." + end +end