On 12/15/05, Steve Litt <slitt / earthlink.net> wrote: > On Thursday 15 December 2005 05:50 pm, Jim Freeze wrote: > The preceding has a couple typos that keep it from running. The > following cures the typos, and also adds an argument called > "--myflag" that is a flag that can go on or off, but errors out if > you try to give it an argument: Thanks for fixing the errors. I should have mentioned that it was untested. And thanks for adding the shebang. Forgot that too. > #!/usr/bin/env ruby > require 'rubygems' > require 'commandline' > > class App < CommandLine::Application > def initialize > synopsis "[-d] [-s [opt_arg]] [-o req_arg]" > short_description "A sample program" > option :names => %w(--short -s), > :arity => [0,1], > :arg_description => "opt_arg", > :opt_found => get_arg, > :opt_not_found => nil > > option :names => %w(--offset -o), > :arg_description => "req_arg", > :opt_found => get_args > > option :help > option :names => %w(--myflag -m), > :arity => [0,0], > :arg_description => "flag", > :opt_found => get_arg A flag option can be written as: option :flag, :names => %w(--myflag -m), The get_arg won't do anything since there is no argment for this option. > end > > def main > puts "Short arg is=>#{opt["--short"]}<" unless opt["--short"].nil? > puts "Offset arg is=>#{opt["--offset"]}<" > puts "Myarg arg is=>#{opt["--myflag"]}<" > end > > end#class App > > > -- Jim Freeze