Class: Simulacrum::CLI::Parser
- Inherits:
-
Object
- Object
- Simulacrum::CLI::Parser
- 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
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(stdout = $stdout) ⇒ Parser
constructor
A new instance of Parser.
- #parse(args, _return = true) ⇒ Object
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_separator add_version add_help end |
Instance Attribute Details
#stdout ⇒ Object (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) ['files'] = args if args.size > 0 OpenStruct.new(.merge()) rescue OptionParser::InvalidOption, OptionParser::AmbiguousOption args = %w(--help) _return = false retry rescue OptionsHandled _return end |