From: Roger Nordqvist Date: 2007-10-09T18:52:45+09:00 Subject: Re: optparse and required switches This is what I came up with for required options. Is this the "ruby way" of doing it or? require 'optparse' options = {} OptionParser.new do |o| o.banner = "Usage: #$0 [options]" o.on("-s", "--server s", "Get servername to connect to") do |s| options[:server] = s end o.on("-u", "--username u", "Get username to connect as") do |u| options[:username] = u end o.on("-p", "--password p", "Get password for user username") do |p| options[:password] = p end o.on("-f", "--filename f", "Remote path and filename to tail") do |f| options[:filename] = f end o.on("-F", "--follow", "Use -f/--follow with remote tail command") do |follow| options[:follow] = follow end end.parse! # Check to see if we got the required arguments needed? required_opts = [:server, :username, :password, :filename] required_opts.each do |opt| if options.has_key?(opt) next else puts "Required option --#{opt} missing." end end -- Posted via http://www.ruby-forum.com/.