Class: Abt::Cli::ArgumentsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/abt/cli/arguments_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments) ⇒ ArgumentsParser

Returns a new instance of ArgumentsParser.



8
9
10
# File 'lib/abt/cli/arguments_parser.rb', line 8

def initialize(arguments)
  @arguments = arguments
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



6
7
8
# File 'lib/abt/cli/arguments_parser.rb', line 6

def arguments
  @arguments
end

Instance Method Details

#parseObject



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

def parse
  result = AriList.new
  rest = arguments.dup

  # If the first arg is a flag, it's for a global command
  result << Ari.new(flags: take_flags(rest)) if flag?(rest.first)

  until rest.empty?
    (scheme, path) = rest.shift.split(":")
    flags = take_flags(rest)

    result << Ari.new(scheme: scheme, path: path, flags: flags)
  end

  result
end