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
|
# File 'lib/aliyun_exmail_csv_generator/optparser.rb', line 7
def self.parse(args)
options = OpenStruct.new
opt_parser = OptionParser.new do |opts|
opts.banner = 'Usage: aliyun_exmail_csv_generator [options] name_list_file'
opts.on('-o', '--output OUTPUT', 'Output file path') do |output|
options.output = output
end
opts.on('-d', '--dept DEPT', 'Set the department of accounts') do |dept|
options.department = dept
end
opts.on('-p', '--password PASSWORD', 'Set the default password of accounts') do |password|
options.password = password
end
opts.on_tail('-v', '--version', 'Show this version') do
puts AliyunExmailCSVGenerator::VERSION
exit
end
opts.on_tail('-h', '--help', 'Show this message') do
puts opts
exit
end
end
opt_parser.parse!(args)
name_list = []
ARGF.each_line do |line|
line.strip!
name_list << line.strip unless line.empty?
end
unless options.department
puts "Input the department (type enter for default: #{Account::DEFAULT_OPTIONS[:department]}):"
department = $stdin.gets.strip!
options.department = department unless department.empty?
end
accounts = Account.from(name_list, options)
output = options.output || 'output.csv'
Exporter.accounts_to_csv(accounts, output)
end
|