Module: UnimatrixParser::ClassMethods

Defined in:
lib/unimatrix_parser.rb

Overview


Class Methods

Instance Method Summary collapse

Instance Method Details

#educate_if_emptyObject



26
27
28
29
30
31
32
# File 'lib/unimatrix_parser.rb', line 26

def educate_if_empty
  if ARGV.empty?
    parser = initialize_parser
    parser.educate
    exit
  end
end

#option(name, description = "", options = {}) ⇒ Object



12
13
14
15
16
# File 'lib/unimatrix_parser.rb', line 12

def option( name, description = "", options = {} ) 
  option = Option.new( name, description, options )
  @options = [] if @options.nil?
  @options << option
end

#optionsObject



43
44
45
46
47
48
# File 'lib/unimatrix_parser.rb', line 43

def options
  parser = initialize_parser
  with_standard_exception_handling( parser ) do 
    parser.parse( ARGV )
  end
end

#stop_on_unknownObject



22
23
24
# File 'lib/unimatrix_parser.rb', line 22

def stop_on_unknown
  @stop_on_unknown = true
end

#synopsis(synopsis = nil) ⇒ Object



18
19
20
# File 'lib/unimatrix_parser.rb', line 18

def synopsis( synopsis = nil )
  @synopsis = synopsis
end

#with_standard_exception_handling(parser) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/unimatrix_parser.rb', line 34

def with_standard_exception_handling( parser )
  yield
rescue CommandlineError => error
  parser.die( error.message, nil, error.error_code )
rescue HelpNeeded
  parser.educate
  exit
end