Module: App

Defined in:
lib/miniparse/app.rb

Constant Summary collapse

ERR_NOT_FOUND =

error exit codes

3
ERR_IO =
4

Class Method Summary collapse

Class Method Details

.configure_parser(program_description = nil, &block) ⇒ Object



33
34
35
36
37
38
# File 'lib/miniparse/app.rb', line 33

def self.configure_parser(program_description = nil,&block)
  reset_parser
  @program_desc = program_description
  @do_configure_parser = block
  nil    
end

.debug(msg) ⇒ Object



25
26
27
# File 'lib/miniparse/app.rb', line 25

def self.debug(msg)
  $stdout.puts "debug: #{msg}"    if App.options[:debug]
end

.error(msg) ⇒ Object



13
14
15
# File 'lib/miniparse/app.rb', line 13

def self.error(msg)
  $stderr.puts "error: #{msg}"  
end

.info(msg) ⇒ Object



21
22
23
# File 'lib/miniparse/app.rb', line 21

def self.info(msg)
  $stdout.puts "info: #{msg}"  
end

.optionsObject



29
30
31
# File 'lib/miniparse/app.rb', line 29

def self.options
  parser.options  
end

.parserObject

lazy parser creation



41
42
43
44
45
46
47
# File 'lib/miniparse/app.rb', line 41

def self.parser
  return @parser   if @parser
  @parser = Miniparse::Parser.new(@program_desc)
  parser.add_option("--debug", nil, negatable: false)
  @do_configure_parser.call(parser)
  parser
end

.reset_parserObject

re-initialize the parser (but doesn’t affect the configuration)



50
51
52
# File 'lib/miniparse/app.rb', line 50

def self.reset_parser
  @parser = nil
end

.warn(msg) ⇒ Object



17
18
19
# File 'lib/miniparse/app.rb', line 17

def self.warn(msg)
  $stderr.puts "warning: #{msg}"  
end