module Ratch # = Runmode # # The Runmode class encapsulates common options for command line scripts. # The built-in modes are: # # force # trace # debug # dryrun -or- noharm # silent -or- quiet # verbose # class Runmode def self.load_argv! options = { :force => %w{--force}.any?{ |x| ARGV.delete(x) }, :trace => %w{--trace}.any?{ |x| ARGV.delete(x) }, :debug => %w{--debug}.any?{ |x| ARGV.delete(x) }, :dryrun => %w{--noharm --dryrun --dry-run}.any?{ |x| ARGV.delete(x) }, :silent => %w{--silent --quiet}.any?{ |x| ARGV.delete(x) }, :verbose => %w{--verbose}.any?{ |x| ARGV.delete(x) } } new(options) end def initialize(options={}) options.rekey(&:to_sym) @force = options[:force] @trace = options[:trace] @debug = options[:debug] @noharm = options[:noharm] || options[:dryrun] @silent = options[:silent] || options[:quiet] @verbose = options[:verbose] end attr_accessor :force attr_accessor :trace attr_accessor :verbose attr_accessor :silent attr_accessor :debug attr_accessor :noharm alias_method :dryrun, :noharm alias_method :dryrun=,:noharm alias_method :quiet, :silent alias_method :quiet=, :silent= def force? ; @force ; end def trace? ; @trace ; end def debug? ; @debug ; end def noharm? ; @noharm ; end def dryrun? ; @noharm ; end def quiet? ; @silent ; end def verbose? ; @verbose ; end end end