| Class | Daemons::Optparse |
| In: |
lib/daemons/cmdline.rb
|
| Parent: | Object |
| usage | [R] |
# File lib/daemons/cmdline.rb, line 8
8: def initialize(controller)
9: @controller = controller
10: @options = {}
11:
12: @opts = OptionParser.new do |opts|
13: opts.banner = ""
14:
15: # opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
16: # @options[:verbose] = v
17: # end
18:
19: opts.on("-t", "--ontop", "Stay on top (does not daemonize)") do |t|
20: @options[:ontop] = t
21: end
22:
23: opts.on("-f", "--force", "Force operation") do |t|
24: @options[:force] = t
25: end
26:
27: opts.on("-n", "--no_wait", "Do not wait for processes to stop") do |t|
28: @options[:no_wait] = t
29: end
30:
31: #opts.separator ""
32: #opts.separator "Specific options:"
33:
34:
35: opts.separator ""
36: opts.separator "Common options:"
37:
38: # No argument, shows at tail. This will print an options summary
39: opts.on_tail("-h", "--help", "Show this message") do
40: #puts opts
41: #@usage =
42: controller.print_usage()
43:
44: exit
45: end
46:
47: # Switch to print the version.
48: opts.on_tail("--version", "Show version") do
49: puts "daemons version #{Daemons::VERSION}"
50: exit
51: end
52: end
53:
54: begin
55: @usage = @opts.to_s
56: rescue ::Exception # work around a bug in ruby 1.9
57: @usage = " -t, --ontop Stay on top (does not daemonize)\n -f, --force Force operation\n -n, --no_wait Do not wait for processes to stop\n\n Common options:\n -h, --help Show this message\n --version Show version\n"
58: end
59: end
Return a hash describing the options.
# File lib/daemons/cmdline.rb, line 74
74: def parse(args)
75: # The options specified on the command line will be collected in *options*.
76: # We set default values here.
77: #options = {}
78:
79:
80: ##pp args
81: @opts.parse(args)
82:
83: return @options
84: end