Class: Hotspots::OptionsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/hotspots/options_parser.rb

Overview

:nodoc: all

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptionsParser

Returns a new instance of OptionsParser.



23
24
25
# File 'lib/hotspots/options_parser.rb', line 23

def initialize
  @options = self.class.default_options
end

Class Method Details

.default_optionsObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/hotspots/options_parser.rb', line 9

def default_options
  {
    :time            => 15,
    :repository      => ".",
    :file_filter     => "",
    :message_filters => [""],
    :cutoff          => 0,
    :verbose         => false,
    :exit_strategy   => OptionBasedExit::Noop.new,
    :colour          => false,
  }
end

Instance Method Details

#parse(*args) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/hotspots/options_parser.rb', line 27

def parse(*args)
  parser = new_option_parser
  begin
    parser.parse args
  rescue ::OptionParser::InvalidOption, ::OptionParser::InvalidArgument => ex
    @options[:exit_strategy] = OptionBasedExit::Error.new(:code => 1, :message => (ex.to_s << "\nUse -h for help\n"))
  end
  @options
end