Class: Rspider::OptParser

Inherits:
Hash
  • Object
show all
Defined in:
lib/rspider/OptParser.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ OptParser

Returns a new instance of OptParser.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rspider/OptParser.rb', line 3

def initialize(args)
	super()
	self[:conf]=""
	self[:env]="TEST"
	self[:debug]="on"
	opts=OptionParser.new do |opt|
		opt.banner="Usage:#$0 [options]"
		
		opt.on("-c","--conf [STRING]",
			'The Configuration File') do |confFile|
			confFile.chomp!
			if confFile == "" 
				puts "No configuration file given"
				exit
			end
			if confFile.nil?
				puts "Configuration not specifed"
				exit
			end
			if !File.file?(confFile) 
				puts "Configuration #{confFile} not exists"
				exit
			end
			self[:conf]=confFile
		end
		opt.on("-e","--env [STRING]",
			'The Enviroment ') do |env|
			if env.upcase =="PRO"
				env="PRO"
			else
				env="TEST"
			end
			self[:env]=env
		end
		opt.on("-d","--debug [on|off]",'show debug messages') do |d|
			if d.upcase == "ON"
				d="on"
			else
				d="off"
			end
			self[:debug]=d
		end
		opt.on("-h","--help",'display this help and exit') do 
			puts opt
			exit
		end
	end
	opts.parse!(args)
end