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