A simple class to help process command line options and enforce any
restrictions. Simply instantiate a CommandLine object and the mode
,
arg
and overrides
instance variables will be set.
Because this is a singleton class, its (only) instance must be created with
the instance
method (and not new
).
Command line options and arguments. NOTE: The Help class is sensitive to the formatting of this section.
Parse the command line arguments, making sure things are okay. Stores the
option mode and the argument of the option plus any configuration
overrides, if any, specified by --override
# File buryspam.rb, line 1481 def initialize begin @mode = nil OPTS.each do |opt, arg| # Treat --override specially since it can be used in conjunction # with other modes. if opt == '--override' (@overrides ||= []) << arg next end unless @mode.nil? raise Error, "Cannot operate in two modes: --#{@mode} and #{opt}." end @mode = opt.gsub(/^--/, "").to_sym case @mode when :grep @arg = Config::Converter.regex(@mode, arg) when :help, :log @arg = arg end end rescue GetoptLong::MissingArgument, GetoptLong::InvalidOption raise Error, "Use the '-h' option to get help." end # Filter, decode, grep and color modes treat the remaining command line # arguments as mboxes. If we are not in any of these modes, but there are # still command line arguments available, then ignore the remaining command # line arguments with a warning. unless ARGV.size == 0 || [:filter, :decode, :grep, :colour].include?(@mode) $stderr.puts "Warning: superfluous command line arguments ignored." ARGV.clear end end