Method: CloudFlock::App#parse_options

Defined in:
lib/cloudflock/app.rb

#parse_options(options = {}) ⇒ Object

Public: Parse options and expose global options which are expected to be useful in any CLI application.

options - Hash containing already-set options.

Yields the OptionsParser object in use if a block is given.

Returns a Hash.



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
# File 'lib/cloudflock/app.rb', line 101

def parse_options(options = {})
  opts = OptionParser.new

  yield opts if block_given?

  opts.separator ''
  opts.separator 'Global Options:'

  opts.on('-c', '--config FILE', 'Specify configuration file') do |file|
    options[:config_file] = File.expand_path(file)
  end

  opts.on_tail('--version', 'Show Version Information') do
    puts "CloudFlock v#{CloudFlock::VERSION}"
    exit
  end

  opts.on_tail('-?', '--help', 'Show this Message') do
    puts opts
    exit
  end

  opts.parse!(ARGV)

  load_config_if_present(options)
rescue OptionParser::MissingArgument, OptionParser::InvalidOption => error
  puts error.message.capitalize
  puts
  ARGV.clear
  ARGV.unshift('-?')
  retry
end