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
|
# File 'lib/imagesorter/option_parser.rb', line 16
def self.parse(argv)
options = OpenStruct.new(DEFAULT_OPTIONS)
parser = ::OptionParser.new do |opts|
opts.banner = 'Usage: imagesorter [options]'
opts.on('-s', '--source SOURCE_DIR', 'Source directory') do |source|
options.source = source
end
opts.on('-d', '--dest DESTINATION_DIR', 'Destination directory (will be created if it does not exist)') do |dest|
options.dest = dest
end
opts.on('-t', '--threads THREADS', "Number of threads to run the processing in (default is #{options.threads})") do |threads|
options.threads = threads
end
opts.on('-m', '--move', 'Move rather than copy') do
options.copy_mode = :move
end
opts.on('-e', '--extensions EXTENSIONS', Array, "What extensions to include (default is #{options.extensions.join(',')})") do |extensions|
options.extensions = extensions
end
opts.on('-r', '--recursive', "Iterate source recursively (default is #{options.recursive})") do |recursive|
options.recursive = recursive
end
opts.on('-l', '--logfile LOGFILE', 'Write message to given logfile. Default output is STDOUT') do |logfile|
options.logfile = logfile
end
opts.on('--locale LOCALE', "Locale to use (default is #{options.locale})") do |locale|
options.locale = locale
end
opts.on('--destination-format DESTINATION_FORMAT', "Destination format (default is #{options.destination_format})") do |destination_format|
options.destination_format = destination_format
end
opts.on('--[no-]silent', 'Run silently') do |silent|
options.silent = silent
end
opts.on('--[no-]test', 'Do a test-run without touching any files') do |test|
options.test = test
end
opts.separator ''
opts.separator 'Common options:'
opts.on_tail('-h', '--help', 'Show this message') do
puts opts
exit
end
opts.on('--verbose', 'Increase log message verbosity') do |verbose|
options.verbose = verbose
end
opts.on_tail('-v', '--version', 'Show version') do
puts Imagesorter::Gem.version
exit
end
end
parser.parse!(argv)
validate_mandatory_options!(options)
options
rescue ::OptionParser::InvalidOption, ::OptionParser::MissingArgument => e
puts e.to_s
puts parser
exit
end
|