Class: ECG::OptionParser

Inherits:
OptionParser
  • Object
show all
Includes:
Singleton
Defined in:
lib/ecg/option_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptionParser

Returns a new instance of OptionParser.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ecg/option_parser.rb', line 12

def initialize
  super

  @args = ARGV.dup
  @trim_mode = '<>'

  on_tail(
    '-t', '--trim-mode MODE', %(Set ERB's trim_mode. Default is "<>".)
  ) do |v|
    @trim_mode = v
  end
  on_tail('-V', '--version', 'Print version information') do
    puts ver
    exit
  end
  on_tail('-h', '--help', 'Print this help message', &method(:print_help))
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



10
11
12
# File 'lib/ecg/option_parser.rb', line 10

def args
  @args
end

#trim_modeObject (readonly)

Returns the value of attribute trim_mode.



10
11
12
# File 'lib/ecg/option_parser.rb', line 10

def trim_mode
  @trim_mode
end

Instance Method Details



30
31
32
# File 'lib/ecg/option_parser.rb', line 30

def banner
  'Usage: ecg [config.{json,yaml}] [options]'
end

#parse!Object



36
37
38
39
40
41
42
43
# File 'lib/ecg/option_parser.rb', line 36

def parse!
  print_help(false) if @args.empty?

  super(@args)
rescue InvalidOption => e
  warn e
  print_help(false)
end

#versionObject



45
46
47
# File 'lib/ecg/option_parser.rb', line 45

def version
  VERSION
end