G
GGarramuno
Okay, as a way of returning the favor for all my recent silly
questions, I've uploaded a first release of the ruby port of Damian
Conway's Getopt:eclare (written originally for Perl).
It is located at:
http://rubyforge.org/projects/getoptdeclare/
Library has been tested on Windows only, albeit it should work on all
platforms.
Let me know how it goes and what could be improved, in either the
distribution, the code or whatever.
Getopt:eclare is yet another command-line argument parser, one which
is specifically designed to be powerful but exceptionally easy to use.
It supports many options not supported by optparser or getoptlong as
well as it has a simpler syntax.
To parse the command-line in +ARGV+, one simply creates a
Getopt:eclare object, by passing Getopt:eclare::new() a
specification of the various parameters that may be encountered:
args = Getopt:eclare.new(specification)
The specification is a single string such as this:
specification = %q(
[tight]
-a Process all data
-b <t:n> Set mean byte length threshold to <t>
{ bytelen = t }
+c <FILE> Create new file <FILE>
--del Delete old file
{ delold() }
delete [ditto]
e <h:i>x<w:i> Expand image to height <h> and width <w>
{ expand(h,w) }
-F <file>... Process named file(s)
{ defer( proc { file.each {|i|
process(i) } } ) }
=getrand [<n:i>] Get a random number
(or, optionally, <n> of them)
{ n = 1 unless !n.empty? }
-- Traditionally indicates end of arguments
{ finish }
)
in which the syntax of each parameter is declared, along with a
description and (optionally) one or more actions to be performed
when
the parameter is encountered. The specification string may also
include other usage formatting information (such as group headings
or
separators) as well as standard Ruby comments (which are ignored).
Calling Getopt:elare::new() parses the contents of the array
+ARGV+,
extracting any arguments which match the parameters defined in the
specification string, and storing the parsed values as hash elements
within the new Getopt:eclare object being created.
Other features of the Getopt:eclare package include:
* The use of full Ruby regular expressions to constrain matching
of parameter components.
* Automatic generation of error, usage and version information.
* Optional conditional execution of embedded actions (i.e. only on
successful parsing of the entire command-line)
* Strict or non-strict parsing (unrecognized command-line elements
may either
trigger an error or may simply be left in +ARGV+
* Declarative specification of various inter-parameter relationships
(for
example, two parameters may be declared mutually exclusive and
this
relationship will then be automatically enforced).
* Intelligent clustering of adjacent flags (for example: the
command-line sequence "-a -b -c" may be abbreviated to "-abc",
unless
there is also a <tt>-abc</tt> flag declared).
* Selective or global case-insensitivity of parameters.
* The ability to parse files (especially configuration files)
instead of
the command-line.
questions, I've uploaded a first release of the ruby port of Damian
Conway's Getopt:eclare (written originally for Perl).
It is located at:
http://rubyforge.org/projects/getoptdeclare/
Library has been tested on Windows only, albeit it should work on all
platforms.
Let me know how it goes and what could be improved, in either the
distribution, the code or whatever.
Getopt:eclare is yet another command-line argument parser, one which
is specifically designed to be powerful but exceptionally easy to use.
It supports many options not supported by optparser or getoptlong as
well as it has a simpler syntax.
To parse the command-line in +ARGV+, one simply creates a
Getopt:eclare object, by passing Getopt:eclare::new() a
specification of the various parameters that may be encountered:
args = Getopt:eclare.new(specification)
The specification is a single string such as this:
specification = %q(
[tight]
-a Process all data
-b <t:n> Set mean byte length threshold to <t>
{ bytelen = t }
+c <FILE> Create new file <FILE>
--del Delete old file
{ delold() }
delete [ditto]
e <h:i>x<w:i> Expand image to height <h> and width <w>
{ expand(h,w) }
-F <file>... Process named file(s)
{ defer( proc { file.each {|i|
process(i) } } ) }
=getrand [<n:i>] Get a random number
(or, optionally, <n> of them)
{ n = 1 unless !n.empty? }
-- Traditionally indicates end of arguments
{ finish }
)
in which the syntax of each parameter is declared, along with a
description and (optionally) one or more actions to be performed
when
the parameter is encountered. The specification string may also
include other usage formatting information (such as group headings
or
separators) as well as standard Ruby comments (which are ignored).
Calling Getopt:elare::new() parses the contents of the array
+ARGV+,
extracting any arguments which match the parameters defined in the
specification string, and storing the parsed values as hash elements
within the new Getopt:eclare object being created.
Other features of the Getopt:eclare package include:
* The use of full Ruby regular expressions to constrain matching
of parameter components.
* Automatic generation of error, usage and version information.
* Optional conditional execution of embedded actions (i.e. only on
successful parsing of the entire command-line)
* Strict or non-strict parsing (unrecognized command-line elements
may either
trigger an error or may simply be left in +ARGV+
* Declarative specification of various inter-parameter relationships
(for
example, two parameters may be declared mutually exclusive and
this
relationship will then be automatically enforced).
* Intelligent clustering of adjacent flags (for example: the
command-line sequence "-a -b -c" may be abbreviated to "-abc",
unless
there is also a <tt>-abc</tt> flag declared).
* Selective or global case-insensitivity of parameters.
* The ability to parse files (especially configuration files)
instead of
the command-line.