forked from oleander/git-fame-rb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-fame
executable file
·58 lines (51 loc) · 2.54 KB
/
git-fame
1
2
3
4
5
6
7
8
9
10
11
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
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env ruby
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
require "git_fame"
require "trollop"
opts = Trollop::options do
version "git-fame #{GitFame::VERSION} (c) 2012-#{Date.today.year} Linus Oleander"
opt :repository, "What git repository should be used?", default: "."
opt :sort, "What should the printed table be sorted by? #{GitFame::SORT.join(", ")}", default: "loc", type: String
opt :"hide-progressbar", "Hide progressbar", default: false
opt :whitespace, "Ignore whitespace changes", default: false
opt :"by-type", "Group line counts by file extension (i.e. .rb, .erb, .yml)", default: false
opt :include, "Comma separated, glob file path to include. I.e path/*.rb", default: "", type: String
opt :exclude, "Comma separated, glob file path to exclude. I.e any/**/path/*", default: "", type: String
opt :extension, "Comma-separated list of extensions to consider, leave blank for all", default: "", type: String
opt :branch, "Branch to run on", default: "master", type: String
opt :format, "Format (pretty/csv)", default: "pretty", type: String
opt :after, "Only use commmits after this date. Format: yyyy-mm-dd. Note that the given date is included", type: String
opt :before, "Only use commits before this date. Format: yyyy-mm-dd. Note that the given date is included", type: String
opt :verbose, "Print shell commands used by git-fame", default: false
opt :timeout, "Set timeout in seconds for each git command. Turn off by using -1", type: Integer, default: GitFame::CMD_TIMEOUT
opt :everything, "Images and binaries are ignored by default. Include them as well", default: false
end
unless GitFame::SORT.include?(opts[:sort])
Trollop::die :sort, "must be one of the following; #{GitFame::SORT.join(", ")}"
end
if opts[:timeout] != -1 and opts[:timeout] <= 0
Trollop::die :timeout, "must be positive"
end
begin
fame = GitFame::Base.new({
repository: opts[:repository],
progressbar: ! opts[:"hide-progressbar"],
sort: opts[:sort],
whitespace: opts[:whitespace],
by_type: opts[:"by-type"],
include: opts[:include],
exclude: opts[:exclude],
extensions: opts[:extension],
branch: opts[:branch],
after: opts[:after],
before: opts[:before],
verbose: opts[:verbose],
everything: opts[:everything],
timeout: opts[:timeout]
})
opts[:format] == "csv" ? fame.csv_puts : fame.pretty_puts
rescue GitFame::Error => e
Trollop::die e.message
rescue Timeout::Error
Trollop::die "Maximum timeout of #{opts[:timeout]} sec exceed. Try passing --timeout=<sec> or -1 for no timeout"
end