class Raheui::Option

Handle command line options.

Public Class Methods

new() click to toggle source

Initialize a Option.

# File lib/raheui/option.rb, line 9
def initialize
  @options = {}
end

Public Instance Methods

parse(args) click to toggle source

Parse the passed arguments to a Hash.

args - An Array of Strings containing options.

Returns an Array consists of a Hash options and an Array of String

remaining arguments.
# File lib/raheui/option.rb, line 19
def parse(args)
  OptionParser.new do |opts|
    opts.banner = 'Usage: raheui [options] [file]'

    add_options(opts)
  end.parse!(args)
  [@options, args]
end

Private Instance Methods

add_options(opts) click to toggle source

Add command line options to OptionParser.

opts - An OptionParser object to add options.

Returns nothing.

# File lib/raheui/option.rb, line 35
def add_options(opts)
  opts.on('-h', '--help', 'Print this message.') do
    puts opts
    exit 0
  end

  opts.on('-v', '--version', 'Print version.') do
    puts Version::STRING
    exit 0
  end
end