I released a new version of Trollop with a couple minor but cool updates.
The best part is the new :io argument type, which uses open-uri to handle
filenames and URIs on the commandline. So you can do something like this:
require 'trollop'
opts = Trollop::options do
opt :source, "Source file (or URI) to print",
:type => :io,
:required => true
end
opts[:source].each { |l| puts "> #{l.chomp}" }
Also, when trying to detect the terminal size, Trollop now tries to `stty
size` before loading curses. This gives better results when running under
screen (for some reason curses clears the terminal when initializing under
screen).
I’ve also cleaned up the documentation quite a bit, expanding the examples on the main page, fixing up the RDoc comments, and generating the RDoc documentation with a modern RDoc, so that things like constants actually get documented.
If you’re still using OptParse, you should really give Trollop a try. I guarantee you’ll write much fewer lines of argument parsing code, and you’ll get all sorts of nifty features like help page terminal size detection.
Hi,
started using Trollop yesterday, I really like it.
I realized one difference to Optparse in the parser and I don’t know if it is intentional: It seems impossible to give a short option and its parameter as one argument.
Example:
Calling this:I realized one difference to Optparse in the parser and I don’t know if it is intentional: It seems impossible to give a short option and its parameter as one argument.
Weird, I didn’t know Optparse supported something like that. I’ve never seen that syntax before.
Supporting it would conflict with Trollop’s short option bundling, e.g. Trollop allows “-p -e” to be written as “-pe”. Since that’s a standard feature (e.g. ruby itself!) I’m not eager to interfere with it.
OK, thanks.
As far as I know, Optparse (and GNU getopt) allows “-a -b -c 12” (where -a and -b are flags, only -c gets/need a parameter) to be given as “-abc12”, but not “-c12ab”. Only the last option can take a parameter.
As far as I know, Optparse (and GNU getopt) allows “-a -b -c 12” (where -a and -b are flags, only -c gets/need a parameter) to be given as “-abc12”, but not “-c12ab”. Only the last option can take a parameter.
Ah, I see. Yes, I would like to support that. Shouldn’t be too hard of a patch.
Thanks!