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
|
# File 'lib/git/duo/cli.rb', line 7
def self.start
parser = OptionParser.new do |opts|
puts current_repo.committer if ARGV.empty?
opts.on '--add AUTHOR', '-a AUTHOR', 'Add an author. Format: "key Firstname Lastname <[email protected]>"' do |string|
current_repo.authors = Author.import string
end
opts.on '--list', '-l', 'Lists the authors in the repository' do
puts current_repo.authors
end
opts.on '--email EMAIL', '-e EMAIL', 'Set email format. Format: [email protected]' do |email|
current_repo.email = email
end
opts.on '--import=PATH/TO/REPO', '-i PATH/TO/REPO', 'Import pairs from another repo' do |path|
import_repo = Repo.new path
current_repo.email = import_repo.email
current_repo.authors = import_repo.authors
end
opts.on '-h', 'Show this message' do
puts opts
exit
end
end
parser.parse!
unless ARGV.empty?
authors = ARGV.sort.map do |key|
author = AuthorCollection.new(current_repo.authors).
where(key: key).first
abort "`#{key}` can't be found, see -h on how to add new authors" unless author
Author.new(key: author.key, name: author.name, email: author.email)
end
pair = Pair.new authors
pair.save
puts pair.to_s
end
current_repo.save
rescue OptionParser::MissingArgument
abort "missing required argument\n\n #{parser.help}"
rescue Git::Duo::EmailNotImplementedError
abort "`Email format isn't set, see -h on how to set the email format"
rescue Git::Duo::NotAGitRepository
exit 1
end
|