test for a ruby script with __END__

Ruby code posted by nico-hn
created at 14 Jan 15:50

Edit | Back
1
2
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
#!/usr/bin/env ruby

require 'optparse_plus'

first_value, second_value = nil, nil

OptionParser.new_with_yaml do |opt|
  opt.inherit_ruby_options("E") # Currently, -E and -d only are available options

  opt.on(:first_option) {|status| first_value = status }
  opt.on(:second_option) {|arg| second_value = arg }
  opt.parse!
end

puts "The value returned from the first option is '#{first_value}'"
puts "The value returned from the second option is '#{second_value}'"

__END__
banner: test_program.rb [OPTION]
first_option:
  short: -f
  long: --first
  description: First option for a test script
second_option:
  short: -s [arg]
  long: --second [=arg]
  description: Second option for a test script
728 Bytes in 5 ms with coderay