Path: | lib/optparse.rb |
Last Update: | Tue Jun 30 13:22:25 -0700 2009 |
optparse.rb - command-line option analysis with the OptionParser class.
Author: | Nobu Nakada |
Documentation: | Nobu Nakada and Gavin Sinclair. |
See OptionParser for documentation.
DecimalInteger | = | /\A[-+]?#{decimal}/io | Decimal integer format, to be converted to Integer. | |
OctalInteger | = | /\A[-+]?(?:[0-7]+(?:_[0-7]+)*|0(?:#{binary}|#{hex}))/io | Ruby/C like octal/hexadecimal/binary integer format, to be converted to Integer. | |
DecimalNumeric | = | floatpat # decimal integer is allowed as float also. | Decimal integer/float number format, to be converted to Integer for integer format, Float for float format. |
banner= | -> | set_banner |
for experimental cascading :-) | ||
program_name= | -> | set_program_name |
summary_width= | -> | set_summary_width |
summary_indent= | -> | set_summary_indent |
Parses environment variable env or its uppercase with splitting like a shell.
env defaults to the basename of the program.
Wrapper method for getopts.rb.
params = ARGV.getopts("ab:", "foo", "bar:") # params[:a] = true # -a # params[:b] = "1" # -b1 # params[:foo] = "1" # --foo # params[:bar] = "x" # --bar x
Loads options from file names as filename. Does nothing when the file is not present. Returns whether successfully loaded.
filename defaults to basename of the program without suffix in a directory ~/.options.
Creates an OptionParser::Switch from the parameters. The parsed argument value is passed to the given block, where it can be processed.
See at the beginning of OptionParser for some full examples.
opts can include the following elements:
:NONE, :REQUIRED, :OPTIONAL
Float, Time, Array
[:text, :binary, :auto] %w[iso-2022-jp shift_jis euc-jp utf8 binary] { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
"--switch=MANDATORY" or "--switch MANDATORY" "--switch[=OPTIONAL]" "--switch"
"-xMANDATORY" "-x[OPTIONAL]" "-x"
There is also a special form which matches character range (not full set of regural expression):
"-[a-z]MANDATORY" "-[a-z][OPTIONAL]" "-[a-z]"
"=MANDATORY" "=[OPTIONAL]"
"Run verbosely"
Parses command line arguments argv in order. When a block is given, each non-option argument is yielded.
Returns the rest of argv left unparsed.
Parses command line arguments argv in order when environment variable POSIXLY_CORRECT is set, and in permutation mode otherwise.
Puts option summary into to and returns to. Yields each line if a block is given.
to: | Output destination, which must have method <<. Defaults to []. |
width: | Width of left side, defaults to @summary_width. |
max: | Maximum length allowed for left side, defaults to width - 1. |
indent: | Indentation, defaults to @summary_indent. |
ruby-doc.org is a service of James Britt and Neurogami, a Ruby application development company in Phoenix, AZ.
Documentation content on ruby-doc.org is provided by remarkable members of the Ruby community.
For more information on the Ruby programming language, visit ruby-lang.org.
Want to help improve Ruby's API docs? See Ruby Documentation Guidelines.