Class: Simulacrum::CLI::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/simulacrum/cli/parser.rb

Overview

Option parser for handling options passed into the Simulacrum CLI

This class is mostly borrowed from Cane’s Parser class. Thanks Xav! <3

Defined Under Namespace

Classes: OptionsHandled

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout = $stdout) ⇒ Parser



22
23
24
25
26
27
28
29
30
# File 'lib/simulacrum/cli/parser.rb', line 22

def initialize(stdout = $stdout)
  @stdout = stdout

  add_banner
  add_format_options
  add_separator
  add_version
  add_help
end

Instance Attribute Details

#stdoutObject (readonly)

Returns the value of attribute stdout.



12
13
14
# File 'lib/simulacrum/cli/parser.rb', line 12

def stdout
  @stdout
end

Class Method Details

.parse(args) ⇒ Object



18
19
20
# File 'lib/simulacrum/cli/parser.rb', line 18

def self.parse(args)
  new.parse(args)
end

Instance Method Details

#parse(args, _return = true) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/simulacrum/cli/parser.rb', line 32

def parse(args, _return = true)
  parser.parse!(args)
  options['files'] = args if args.size > 0
  OpenStruct.new(default_options.merge(options))
rescue OptionParser::InvalidOption,
       OptionParser::AmbiguousOption
  args = %w(--help)
  _return = false
  retry
rescue OptionsHandled
  _return
end