Class: GitCompound::Command::Arguments::Parser
- Inherits:
-
Object
- Object
- GitCompound::Command::Arguments::Parser
- Defined in:
- lib/git_compound/command/arguments/parser.rb
Overview
Class responsible for parsing ARGV for given procedure
Instance Method Summary collapse
- #command ⇒ Object
- #global ⇒ Object
-
#initialize(argv, global) ⇒ Parser
constructor
A new instance of Parser.
- #options ⇒ Object
- #procedure ⇒ Object
Constructor Details
#initialize(argv, global) ⇒ Parser
Returns a new instance of Parser.
7 8 9 10 |
# File 'lib/git_compound/command/arguments/parser.rb', line 7 def initialize(argv, global) @global = global @args = format_arguments(argv) end |
Instance Method Details
#command ⇒ Object
39 40 41 |
# File 'lib/git_compound/command/arguments/parser.rb', line 39 def command @args.find { |arg| arg.is_a?(String) } end |
#global ⇒ Object
35 36 37 |
# File 'lib/git_compound/command/arguments/parser.rb', line 35 def global @args & @global end |
#options ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/git_compound/command/arguments/parser.rb', line 18 def arguments = @args - @global - [command] found = {} option_each(procedure.) do |name, type| option = type.new(name, arguments) next unless option.valid? arguments -= option.used found.merge!(option.parse) end return found if arguments.empty? raise UnknownArgumentError, "Unknown arguments `#{arguments.inspect}`" end |