From: Holden Glova Date: 2002-03-19T19:40:41+09:00 Subject: Re: Help with getoptlong please TIA :-) -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tue, 19 Mar 2002 12:25, Ray.ravinray@hotmail.com wrote: > I need help with getoptlong . It does fine when I use an option but if I > do not use an option it doesn't do anything. Do I have to pass in an > option with getoptlong? any help or link would be apprecited. I am very > new to ruby but this is frustrating me > > Thanks, > > Ray I just played with getoptlong this weekend for the first time and here is what worked for me. Here is a snippet of something I am playing with, hope this helps somewhat... OPTION_LIST = [ ['--query', '-q', GetoptLong::REQUIRED_ARGUMENT], ['--show', '-s', GetoptLong::REQUIRED_ARGUMENT] ] def usage(msg = nil) $stderr.puts(msg) if msg program_name = File.basename($0) $stderr.puts " usage: #{program_name} [options] [package_name] options: --query query the RAA for a package. Accepts regular expressions and partial names. --show show information about a package. The package must be the complete name of the the package as is in the RAA. " exit 1 end def initialize @package_name = '' opt_parser = GetoptLong.new(*OPTION_LIST) opt_parser.quiet = true usage if ARGV.length == 0 opt_parser.each do |opt, arg| case opt when '--query' package_name = arg @action = proc { query_raa(package_name) } break when '--show' package_name = arg @action = proc { show_from_raa(package_name) } break else usage end end rescue GetoptLong::InvalidOption => error usage(error.message) rescue GetoptLong::MissingArgument => error usage(error.message) end - -- Signed, Holden Glova -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD0DBQE8lxba+mF116Lw2cQRAieiAJURg+MHREbx0zK9tfBknM0RSQ4cAJim+Q2L saqBVXrLxV0QpMH0hyA5 =dDHA -----END PGP SIGNATURE-----