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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/git-pair/command.rb', line 11
def run!(args)
options = OpenStruct.new(:update => true,
:authors => [])
parser = OptionParser.new do |opts|
opts.banner = highlight('General Syntax:')
opts.separator ' git pair [reset | authors | options]'
opts.separator ' '
opts.separator highlight('Options:')
opts.on '-a', '--add AUTHOR', 'Add an author. Format: "Author Name <[email protected]>"' do |author|
options.add_author = Author.new(author)
Config.add_author(options.add_author)
end
opts.on '-r', '--remove NAME', 'Remove an author. Use the full name.' do |name|
options.remove_author = name
Config.remove_author options.remove_author
end
opts.on '-d', '--reset', 'Reset current author to default (global) config' do
options.reset = true
Config.reset
end
opts.on '--install-hook', 'Install a post-commit hook for the current repo. See git-pair/hooks/post-commit for more information.' do
options.symlink = true
end
opts.on '--email EMAIL', 'Add a default email address to be used for pairs' do |email|
puts "Setting email to #{email}"
options.pair_email = email
Config.set_pair_email(options.pair_email)
end
opts.on '-s', "--show 'aa [bb]'", 'Show the string to be used for the commit author field' do |initials|
options.update = false
options.authors = Author.find_all(initials.split(' '))
end
opts.separator ' '
opts.separator highlight('Switching authors:')
opts.separator ' git pair aa [bb] Where AA and BB are any abbreviation of an'
opts.separator ' '*37 + 'author\'s name. You can specify one or more authors.'
opts.separator ' '
opts.separator highlight('Current config:')
opts.separator author_list.split("\n")
opts.separator ' '
opts.separator pair_email.split("\n")
opts.separator ' '
opts.separator current_author_info.split("\n")
end
initials = parser.parse!(args.dup)
initials = initials.map { |e| e.split(' ') }.flatten
if options.authors.empty? && !initials.empty?
options.authors = Author.find_all(initials)
end
if args.empty?
puts parser.help
elsif options.authors && !options.update
puts Display.git_author options.authors
elsif options.symlink
symlink_post_commit_hook
elsif options.authors.empty?
puts author_list
puts
puts current_author_info
else
Config.switch(options.authors)
puts current_author_info
end
rescue OptionParser::MissingArgument
abort "missing required argument", parser.help
rescue OptionParser::InvalidOption, OptionParser::InvalidArgument => e
abort e.message.sub(':', ''), parser.help
rescue NoMatchingAuthorsError => e
abort e.message, "\n" + author_list
rescue MissingConfigurationError => e
abort e.message, parser.help
rescue Author::InvalidAuthorString => e
abort e.message, parser.help
end
|