Class: ArgumentParser

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

Instance Method Summary collapse

Constructor Details

#initialize(commands) ⇒ ArgumentParser

Returns a new instance of ArgumentParser.



3
4
5
# File 'lib/shellutils/argument_parser.rb', line 3

def initialize commands
	@commands = commands
end

Instance Method Details

#parse(params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/shellutils/argument_parser.rb', line 7

def parse params
	params[0] = params[0] ? params[0].downcase : 'help'
	command_name = params[0]
	command_executed = false
	@commands.each do |command|
		if command.accepts_shell_command?(command_name) 
			command.execute_from_shell params
			command_executed = true
		end
	end
	if not command_executed and command_name == "spec"
		# 'spec" is for testing purpose only: do nothing special
	elsif not command_executed
		raise ShellArgumentException.new command_name
	end
end