Class: ReadArgs

Inherits:
Object
  • Object
show all
Defined in:
lib/params/argument_parser.rb

Class Method Summary collapse

Class Method Details

.read_arguments(argv, parsed_arguments, commands = nil) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/params/argument_parser.rb', line 2

def self.read_arguments(argv, parsed_arguments, commands = nil)
  argv.each { |arg|
    if arg.start_with?("--")
      words = arg[2,arg.length-2].split('=')
      parsed_arguments[words[0]]=words[1]
    elsif commands != nil and not commands.key?(arg)
      puts "Unknown command '%s'." % arg
      return false
    else
      if parsed_arguments.key? arg
        puts "Parse error, two commands found %s and %s" % parsed_arguments["command"], arg
        return false
      end
      parsed_arguments["command"] = arg
    end
  }

  return false unless commands == nil or parsed_arguments["command"] != nil
  return false unless commands == nil or parsed_arguments["command"] != ""

  return true
end