Introducing the optparse-simple gem

require 'optparse-simple'

options =<<EOF
dxxx -d --dxxx n/a false 
idxxx n/a n/a \\w+ false
EOF

ops = OptParseSimple.new(options).parse %w(-d 4)
#=> {:dxxx=>nil, :idxxx=>"4"}

# from the command-line this would be typed as follows:
# tes -d 4  


The above code demonstrates how command-line arguments can be parsed from a Ruby script. I wanted to test a script from the command-line that would supply the following:

Optparse-simple in the simplest form reads rows of options, with each row field being separated by a space. The fields are as follows:

Note: if a field is not applicable, set the value to n/a.

Resources

Tags:
Source:
2047hrs.txt
Published:
16-01-2013 20:47