Class: OptionReader

Inherits:
Object
  • Object
show all
Defined in:
lib/yakr/optionreader.rb

Overview

optionreader.rb

Copyright (c) 2012, Marc Ransome <[email protected]>

This file is part of Yakr.

Yakr is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Yakr is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Yakr.  If not, see <http://www.gnu.org/licenses/>.

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object



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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/yakr/optionreader.rb', line 24

def self.parse(args)

	options = OpenStruct.new

	opts = OptionParser.new do |opts|
		opts.banner = "Usage: #{File.basename($0)} -c HOST -p PORT | -l PORT [-m NUM]"

		opts.separator ""
		opts.separator "Client mode options:"

		opts.on("-c", "--connect HOST", "Specify the remote host to connect to") do |host|
			options.connect_host = host
		end

		opts.on("-p", "--port PORT", "Port number for outgoing connection") do |port|
			options.connect_port = port
		end

		opts.separator ""
		opts.separator "Server mode options:"

		opts.on("-l", "--listen PORT", "Port number for incoming connection") do |port|
			options.listen_port = port
		end
		
		opts.on("-m", "--max NUM", "Limit output to NUM lines, then exit") do |lines|
			options.limit_lines = lines
		end
		
		opts.separator ""
		opts.separator "Misc options:"

		opts.on("-v", "--version", "Display version information") do
			puts "#{File.basename($0).capitalize} #{Yakr::VERSION} Copyright (C) 2012 Marc Ransome <[email protected]>"
			puts "This program comes with ABSOLUTELY NO WARRANTY, use it at your own risk."
			puts "This is free software, and you are welcome to redistribute it under"
			puts "certain conditions; see LICENSE.txt for details."
			exit
		end

		opts.on_tail("-h", "--help", "Show this screen") do
			puts opts
			exit
		end
	end

	# parse then remove the remaining arguments
	opts.parse!(args)

	# return the options array
	options

end