Class: Tojour::OptParser
- Inherits:
-
Object
- Object
- Tojour::OptParser
- Defined in:
- lib/tojour/opt_parser.rb
Instance Attribute Summary collapse
-
#argv ⇒ Object
Returns the value of attribute argv.
-
#method ⇒ Object
Returns the value of attribute method.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(argv) ⇒ OptParser
constructor
A new instance of OptParser.
Constructor Details
#initialize(argv) ⇒ OptParser
Returns a new instance of OptParser.
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/tojour/opt_parser.rb', line 7 def initialize(argv) = { is_send_file: false, is_receive_file: false, is_input: false, is_output: false, is_list_file_clients: false, is_list: false, send_filename: nil, port: 9876, key_path: ENV['KEY_PATH'] || %[#{File.dirname(__FILE__)}/../../keys/server.key], csr_path: ENV['CSR_PATH'] || %[#{File.dirname(__FILE__)}/../../keys/server.csr], crt_path: ENV['CRT_PATH'] || %[#{File.dirname(__FILE__)}/../../keys/server.crt] } methods = [ :send_file, :receive_file, :input, :output, :list ] optparse = OptionParser.new do |opts| opts. = 'USAGE: tojour [options] name' opts.on('-s FILE', '--send FILE', 'Transmit a FILE.') do |filename| [:is_send_file] = true [:send_filename] = filename end opts.on('-r', '--receive', 'Receive a file.') do |filename| [:is_receive_file] = true [:receive_filename] = filename end opts.on('-i', '--input', 'Receive input and output to STOUT.') do [:is_input] = true end opts.on('-o', '--output', 'Transmit output from STDIN.') do [:is_output] = true end opts.on('-l', '--list-clients', 'List clients.') do [:is_list] = true end opts.on('-p PORT', '--port PORT', 'Port to wait on.') do |port| [:port] = port end opts.on_tail('-h', '--help', 'Show this message.') do STDERR.puts optparse.help exit end end @options = @argv = optparse.parse(argv) true_values = methods.select { |name| [:"is_#{name}"] == true } @method = true_values.first.to_s.gsub(/^is_/, '').to_sym if true_values.count != 1 STDERR.puts optparse.help exit end end |
Instance Attribute Details
#argv ⇒ Object
Returns the value of attribute argv.
5 6 7 |
# File 'lib/tojour/opt_parser.rb', line 5 def argv @argv end |
#method ⇒ Object
Returns the value of attribute method.
5 6 7 |
# File 'lib/tojour/opt_parser.rb', line 5 def method @method end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/tojour/opt_parser.rb', line 5 def @options end |