Bil Kleb wrote: > Hi, > > I know, I'm slow, but I finally figured out the minimalistic > command line options parsing that zenspider et al use in utilities > like flog and sow (the gem skeleton generator that comes with Hoe). > > Consider, for example, > > #!/usr/bin/env ruby -s > > $r ||= false > > if defined? $h then > puts "usage: #{File.basename $0}" > puts " -h this usage message" > puts " -r recursive" > end > > puts "Recursive option: #$r" > > The secret sauce is the '-s' option passed to the interpreter, > which according to the PickAxe indicates, "Any command-line switches > found after the program filename, but before any filename arguments > or before a --, are removed from ARGV and set to a global variable > named for the switch." It's nice to have that for very short scripts, but for about 50 LOC you can paste in an options parser that permits --foo style options, -xyz as an alias for "-x -y -z", option arguments, argument conversion procs and defaults, "-x123" as an alias for "-x 123", and even a way to interpret "-v -v -v" as thrice verbose. One thing you can't have is _optional_ arguments to options (e.g. an option that takes 0 or 1 arguments). http://redshift.sourceforge.net/argos.rb -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407