Class: HomeQ::Base::Options::Options
- Inherits:
-
Object
- Object
- HomeQ::Base::Options::Options
- Includes:
- Singleton
- Defined in:
- lib/homeq/base/options.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#parser ⇒ Object
Returns the value of attribute parser.
Instance Method Summary collapse
-
#initialize ⇒ Options
constructor
A new instance of Options.
-
#parse ⇒ Object
Return a structure describing the options.
Constructor Details
#initialize ⇒ Options
Returns a new instance of Options.
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/homeq/base/options.rb', line 49 def initialize = OpenStruct.new .log_level = false .config_file = File.join(HOMEQ_APP_ROOT, '/config/homeq.cfg') .queue_name = nil .cp_port = nil .foreground = false .pid_file = false .log_file = false .dump_topology = false .enable_debugging = false @parser = OptionParser.new do |opts| opts. = "Usage: #{File.basename($0)} [options]" opts.separator "" opts.separator "HOMEQ options:" # Mandatory argument. opts.on("-c", "--config-file FILE", "Configuration file; defaults to \n\ #{@options.config_file}") { |c| .config_file = c } opts.on("-q", "--queuename NAME", "This process's queue name") { |q| .queue_name = q } opts.on("-p", "--port PORT", Integer, "Control port to listen on.") { |p| .cp_port = p } opts.on("-l", "--[no-]log-file LOGFILE", "Log to this file; defaults to \n\ #{@options.log_file}") { |o| .log_file = o } opts.on("-P", "--pid-file FILE", "Write pid to this file;\n \ defaults to " + "/var/run/hq_<queuename>.pid") { |p| .pid_file = p } # Boolean switches opts.on("-v", "--[no-]verbose", "Run verbosely. Additively -vvv") do |v| .log_level = 0 unless .log_level .log_level += 1 end opts.on("-f", "--[no-]foreground", "Run in the foreground") do |o| .foreground = o end opts.on("-T", "--print-topology", "Using command line options and config file,\n \ dump a topology in YAML format.") do |o| .dump_topology = o end opts.on("-E", "--print-homeq-env", "Using command line options and config file,\n \ display currently set HOMEQ_ENV.") do |o| .dump_env = o end opts.on("-D", "--enable-debugging", "Enable rdebug debugging") do |o| .enable_debugging = o end opts.separator "" opts.separator "Common options:" opts.on("-h", "--help", "Show this message") do puts opts exit end # Another typical switch to print the version. opts.on("--version", "Show version") do puts OptionParser::Version.join('.') Kernel::exit end end end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
46 47 48 |
# File 'lib/homeq/base/options.rb', line 46 def end |
#parser ⇒ Object
Returns the value of attribute parser.
47 48 49 |
# File 'lib/homeq/base/options.rb', line 47 def parser @parser end |
Instance Method Details
#parse ⇒ Object
Return a structure describing the options.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/homeq/base/options.rb', line 140 def parse # The options specified on the command line will be # collected in *options*. We set default values here. begin @parser.parse!(ARGV) rescue OptionParser::ParseError => pe puts @parser raise end # Add our cute little override method class << def set_configuration(config) @table.each { |k,v| if config.respond_to?(k) && v config.send(k, v) end } end end end |