class Abt::Cli::ArgumentsParser

Attributes

arguments[R]

Public Class Methods

new(arguments) click to toggle source
# File lib/abt/cli/arguments_parser.rb, line 8
def initialize(arguments)
  @arguments = arguments
end

Public Instance Methods

parse() click to toggle source
# 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

Private Instance Methods

delimiter?(part) click to toggle source
# File lib/abt/cli/arguments_parser.rb, line 46
def delimiter?(part)
  part == "--"
end
flag?(part) click to toggle source
# File lib/abt/cli/arguments_parser.rb, line 42
def flag?(part)
  part && part[0] == "-"
end
take_flags(rest) click to toggle source
# File lib/abt/cli/arguments_parser.rb, line 31
def take_flags(rest)
  flags = []

  if flag?(rest.first)
    flags << rest.shift until rest.empty? || delimiter?(rest.first)
    rest.shift if delimiter?(rest.first)
  end

  flags
end