Class: Tomo::CLI::Parser
- Inherits:
-
Object
- Object
- Tomo::CLI::Parser
- Extended by:
- Forwardable
- Includes:
- Tomo::Colors
- Defined in:
- lib/tomo/cli/parser.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
Instance Method Summary collapse
- #after_parse(context_method_name) ⇒ Object
- #arg(spec, values: []) ⇒ Object
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #option(key, spec, desc = nil, values: []) ⇒ Object
- #parse(argv) ⇒ Object
Methods included from Tomo::Colors
Constructor Details
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
13 14 15 |
# File 'lib/tomo/cli/parser.rb', line 13 def context @context end |
Instance Method Details
#after_parse(context_method_name) ⇒ Object
30 31 32 |
# File 'lib/tomo/cli/parser.rb', line 30 def after_parse(context_method_name) after_parse_methods << context_method_name end |
#arg(spec, values: []) ⇒ Object
21 22 23 |
# File 'lib/tomo/cli/parser.rb', line 21 def arg(spec, values: []) rules.add_arg(spec, proc_for(values)) end |
#option(key, spec, desc = nil, values: []) ⇒ Object
25 26 27 28 |
# File 'lib/tomo/cli/parser.rb', line 25 def option(key, spec, desc=nil, values: [], &) rules.add_option(key, spec, proc_for(values), &) usage.add_option(spec, desc) end |
#parse(argv) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tomo/cli/parser.rb', line 34 def parse(argv) state = State.new , literal_argv = split(argv, "--") evaluate(, state, literal: false) evaluate(literal_argv, state, literal: true) check_required_rules(state) invoke_after_parse_methods(state) [*state.args, state.] end |