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
59
60
61
|
# File 'lib/git-pair/command.rb', line 9
def run!(args)
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|
Config.add_author Author.new(author)
end
opts.on '-r', '--remove NAME', 'Remove an author. Use the full name.' do |name|
Config.remove_author name
end
opts.on '-d', '--reset', 'Reset current author to default (global) config' do
Config.reset
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 current_author_info.split("\n")
end
authors = parser.parse!(args.dup)
if args.empty?
puts parser.help
elsif authors.empty?
puts author_list
puts
puts current_author_info
else
Config.switch Author.find_all(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
|