7: def parse_options(argv=nil, version=nil)
8: argv ||= ARGV.dup
9: options = OpenStruct.new
10: opts = OptionParser.new do |opts|
11: yield(opts, options)
12:
13: opts.separator ""
14: opts.separator "Common options:"
15:
16: opts.on_tail("--config=CONFIG",
17: "Specify configuration file written as YAML") do |file|
18: require 'yaml'
19: config = YAML.load(File.read(file)).symbolize_keys
20: Configuration::DEFAULT_CONFIG.update(config)
21: end
22:
23: opts.on_tail("-h", "--help", "Show this message") do
24: puts opts
25: exit
26: end
27:
28: opts.on_tail("--version", "Show version") do
29: puts(version || VERSION)
30: exit
31: end
32: end
33: opts.parse!(argv)
34: [argv, opts, options]
35: end