Method: CommandLion::App#parse

Defined in:
lib/command_lion/app.rb

#parseObject

Parse arguments off of ARGV.



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/command_lion/app.rb', line 306

def parse
  @commands.each do |_, cmd|
    if cmd.flags?
      # or for the || seems to not do what I want it to do...
      next unless argv_index = ARGV.index(cmd.flags.short) || ARGV.index(cmd.flags.long)
    else
      next unless argv_index = ARGV.index(cmd.index.to_s)
    end
    cmd.given = true unless argv_index.nil?
    if cmd.type.nil?
      yield cmd if block_given?
    else
      if parsed = parse_cmd(cmd, flags)
        cmd.arguments = parsed || cmd.default
        yield cmd if block_given?
      elsif cmd.default
        cmd.arguments = cmd.default
        yield cmd if block_given?
      end
    end
  end
end