Class: Daemons::Optparse

Inherits:
Object
  • Object
show all
Defined in:
lib/daemons/cmdline.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ Optparse

Returns a new instance of Optparse.



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
# File 'lib/daemons/cmdline.rb', line 8

def initialize(controller)
  @controller = controller
  @options = {}
  
  @opts = OptionParser.new do |opts|
    #opts.banner = "Usage: example.rb [options]"
    opts.banner = ""
    
    # Boolean switch.
#         opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
#           @options[:verbose] = v
#         end
    
    opts.on("-t", "--ontop", "Stay on top (does not daemonize)") do |t|
      @options[:ontop] = t
    end
    
    opts.on("-f", "--force", "Force operation") do |t|
      @options[:force] = t
    end
    
    #opts.separator ""
    #opts.separator "Specific options:"

    
    opts.separator ""
    opts.separator "Common options:"

    # No argument, shows at tail.  This will print an options summary.
    # Try it and see!
    opts.on_tail("-h", "--help", "Show this message") do
      #puts opts
      #@usage = 
      controller.print_usage()
      
      exit
    end

    # Another typical switch to print the version.
    opts.on_tail("--version", "Show version") do
      puts "daemons version #{Daemons::VERSION}"
      exit
    end
  end  
  
  @usage = @opts.to_s  
end

Instance Attribute Details

#usageObject (readonly)

Returns the value of attribute usage.



6
7
8
# File 'lib/daemons/cmdline.rb', line 6

def usage
  @usage
end

Instance Method Details

#parse(args) ⇒ Object

Return a hash describing the options.



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/daemons/cmdline.rb', line 60

def parse(args)
  # The options specified on the command line will be collected in *options*.
  # We set default values here.
  #options = {}
  
  
  ##pp args
  @opts.parse(args)
  
  return @options
end