-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoptparser.rb
More file actions
50 lines (42 loc) · 1.27 KB
/
optparser.rb
File metadata and controls
50 lines (42 loc) · 1.27 KB
1
2
3
4
5
6
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
require 'optparse'
require 'ostruct'
require 'pp'
class OptParser
def self.parse(args)
options = OpenStruct.new
options.compression_method = false
options.verbose = false
op = OptionParser.new do |opts|
opts.banner = "Usage: sbackup.rb [options]"
opts.separator ""
opts.separator "Options:"
opts.on("-v", "--verbose", "Verbosely list files processed") do |v|
options.verbose = v
end
opts.on("--compress [METHOD]", [:gzip, :bzip2, :zip],
"Select compression method (gzip, bzip2, or zip)") do |method|
options.compression_method = method
end
opts.on_tail("-h", "--help", "Show help message") do |h|
puts opts
exit
end
opts.on_tail("--version", "Show version") do
puts SBackup::Version.join('.')
exit
end
end
begin
op.parse!(args)
options
rescue OptionParser::InvalidOption => e
puts e
puts op
exit 1
rescue OptionParser::InvalidArgument => e
puts e
puts op
exit 1
end
end
end