Class: Utils
- Inherits:
-
Object
- Object
- Utils
- Defined in:
- lib/git-commits-analyzer/utils.rb
Overview
Public: supporting functions for the command-line utility.
Examples:
require 'git-commits-analyzer/utils'
= Utils.()
repos = Utils.get_git_repos(path)
Class Method Summary collapse
Class Method Details
.get_git_repos(path:) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/git-commits-analyzer/utils.rb', line 48 def self.get_git_repos(path:) repos = [] Dir.glob(File.join(path, '*')) do |dir| # Skip files. next if !File.directory?(dir) # Skip directories without .git subdirectory (shortcut to identify repos # with a working dir) or without a HEAD file (shortcut to identify bare # git repositories). next if !File.directory?(File.join(dir, '.git')) && !File.file?(File.join(dir, 'HEAD')) repos << dir end return repos end |
.parse_command_line_options ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/git-commits-analyzer/utils.rb', line 12 def self.() = {} OptionParser.new do |opts| opts. = 'Usage: inspect_contributions.rb [options]' [:authors] = [] # Parse path. opts.on('-p', '--path PATH', 'Specify a path to search for git repositories under') do |path| [:path] = path end # Parse authors. opts.on('-a', '--author EMAIL', 'Include this author in statistics') do |email| [:authors] << email end # Parse output directory. opts.on('-p', '--output PATH', 'Specify a path to output files with collected data') do |output| [:output] = output end # Show usage opts.on_tail('-h', '--help', 'Show this message') do puts opts exit end end.parse! # Check mandatory options. raise OptionParser::MissingArgument, '--author' if [:authors].empty? raise OptionParser::MissingArgument, '--output' if [:output].nil? raise OptionParser::MissingArgument, '--path' if [:path].nil? return end |