You like command-line parsing, but you hate all of the bloat. Why
should you have to create a Hash, then create a parser, then fill
that Hash out then throw the parser away (unless you want to print
out a usage message) and deal with a Hash? Why, for Pete's sake, should
you have to deal with so many objects just to find out what was given
on the command-line?
Well, now you don't have to..
Now parsing is as easy as falling off of a log:
require "rubygems"
require "clip"
p = Clip do |c|
c.optional 's', 'server', :desc => 'The server name', :default => 'localhost'
c.optional 'p', 'port', :desc => 'The port', :default => 8080
c.optional 'f', 'files', :desc => 'Files to upload', :multi => true
c.flag 'v', 'verbose', :desc => 'Make it verbose, man'
end
printf("%10s %-20s\n", "attribute", "value")
[:server, :port, :verbose?].each do |att|
printf("%10s %-20s\n", att, p.send(att))
end
printf("%10s %-20s\n", "files", p.files.inspect)
How can you get this fine library? Easy:
sudo gem install clip