Re: Command-line option parsing
- From: "Gavin Sinclair" <gsinclair@xxxxxxxxx>
- Date: 28 Dec 2005 21:47:21 -0800
Eric J. Roode wrote:
>
> I disagree about the example being all you need.
Please disregard my other reply in this thread. Your points are
perfectly valid and I'll try to improve the documentation.
> Here's the first option in the example:
>
> # Mandatory argument.
> opts.on("-r", "--require LIBRARY",
> "Require the LIBRARY before executing your script") do |lib|
> options.library << lib
> end
>
> I am new to ruby, so I don't know what "options.library << lib" means. I
> thought that that introduced a here-doc string.
The documentation's not at fault here: knowledge of Ruby is assumed :)
> The second example:
>
> # Optional argument; multi-line description.
> opts.on("-i", "--inplace [EXTENSION]",
> "Edit ARGV files in place",
> " (make backup if EXTENSION supplied)") do |ext|
> ...
>
> It took me a lot of staring at the code before it dawned on me that it
> was the *brackets* that made it an optional argument.
That will be easy to point out in the docs. Thanks.
> The final example:
>
> # Another typical switch to print the version.
> opts.on_tail("--version", "Show version") do
> puts OptionParser::Version.join('.')
> exit
> end
>
> I can't figure out how the on_tail method differs from the on method or
> the on_head method. Reading the source isn't helping. The example
> sucks.
It means to show the "--version" option at the end (the "tail") of the
options list.
>
> At the end of the parse() method (and why is it self.parse, not just
> parse?), there is this:
>
> opts.parse!(args)
>
> I can't tell what function that performs for the class.
Hopefully I can clear this up. The difference between parse and parse!
is that parse! swallows ARGV.
> I can't tell how to make an option mandatory, how to configure it so that
> some options require certain others or conflict with certain others.
A "mandatory option" is a contradiction :) You need to test for the
presence of an option in your own code.
> I come from the Perl world. You simply do not release a module to Perl's
> CPAN unless it is thoroughly documented. The vast majority of CPAN
> modules have quite good documentation -- or at least, thorough
> documentation. I'm quite surprised to find that the situation is so
> different in the ruby world.
While not disagreeing in the least, I bet there are plenty of
badly-documented Perl modules, but they're not the often-used ones, so
they don't detract from the "Perl modules are well documented" meme.
Ruby is certainly worse, though!
Gavin
.
- Follow-Ups:
- Re: Command-line option parsing
- From: Daniel Berger
- Re: Command-line option parsing
- References:
- Command-line option parsing
- From: Eric J. Roode
- Re: Command-line option parsing
- From: Robert Klemme
- Re: Command-line option parsing
- From: Eric J. Roode
- Command-line option parsing
- Prev by Date: Re: Locking classes?
- Next by Date: Re: [ANN] apt-sary-0.1
- Previous by thread: Re: Command-line option parsing
- Next by thread: Re: Command-line option parsing
- Index(es):
Relevant Pages
|