module Fuzz::OPTIONS

Public Class Methods

add_config(rcpath) click to toggle source
# File lib/fuzz/options.rb, line 195
def add_config(rcpath)
  log_fatal("inaccessible rc path specified : #{rcpath}") unless File.readable?(rcpath)
  _add_rcpath(rcpath)
end
load_config() click to toggle source
# File lib/fuzz/options.rb, line 156
def load_config
  # first collect config from known (standard and configured) locations
  _rc_paths.collect {|path| File.expand_path(path) }.each do |rcp|
    log(3, "Testing rc path #{rcp}")
    if File.readable?(rcp) && !_loaded_rc_paths.include?(rcp)
      _cfg = Config.new.load(rcp)
      self[:config].merge(_cfg)
      _loaded_rc_paths << rcp
    else
      log(3, "Ignoring #{File.readable?(rcp) ? 'already loaded' : 'inaccessible'} rc path #{rcp}")
    end
  end
  # now scan working path for any rc files unless specified otherwise
  unless self[:no_rc_scan]
    _cwd = File.expand_path(Dir.getwd)
    log(3, "scanning working path #{_cwd} for rc files")
    # first collect any rc files found
    _rcpaths = []
    begin
      _rcp = File.join(_cwd, FUZZRC)
      if File.readable?(_rcp) && !_loaded_rc_paths.include?(_rcp)
        _rcpaths << _rcp
      else
        log(3, "Ignoring #{File.readable?(_rcp) ? 'already loaded' : 'inaccessible'} rc path #{_rcp}")
      end
      break if /\A(.:(\\|\/)|\.|\/)\Z/ =~ _cwd
      _cwd = File.dirname(_cwd)
    end while true
    # now load them in reverse order
    _rcpaths.reverse.each do |_rcp|
      _cfg = Config.new.load(_rcp)
      self[:config].merge(_cfg)
      _loaded_rc_paths << _rcp
    end
  end
  # lastly merge config specified by user on commandline
  self[:config].merge(user_config)
end
options() click to toggle source
# File lib/fuzz/options.rb, line 25
def options
  self
end
reset() click to toggle source
# File lib/fuzz/options.rb, line 145
def reset
  @table.clear
  @table.merge!(_defaults)
  _rc_paths.clear
  _rc_paths << FUZZRC_GLOBAL
  _loaded_rc_paths.clear
  (ENV['FUZZRC'] || '').split(/:|;/).each do |p|
    _add_rcpath(p)
  end
end
user_config() click to toggle source
# File lib/fuzz/options.rb, line 200
def user_config
  @user_config ||= Config.new
end

Protected Class Methods

_add_rcpath(path) click to toggle source
# File lib/fuzz/options.rb, line 133
def _add_rcpath(path)
  if _loaded_rc_paths.include?(File.expand_path(path))
    log(3, "ignoring already loaded rc : #{path}")
  else
    log(3, "adding rc path : #{path}")
    _rc_paths << path
  end
  _rc_paths
end
_defaults() click to toggle source
# File lib/fuzz/options.rb, line 108
def _defaults
  {
    :verbose => (ENV['FUZZ_VERBOSE'] || 1).to_i,
    :recurse => true,
    :apply_fix => false,
    :config => Config.new({
      :follow_symlink => true,
      :exts => [],
      :filenames => [],
      :excludes => [],
      :add_files => false,
      :fzzr_paths => [],
      :fzzr_opts => {},
      :fzzr_excludes => []
    })
  }
end
_loaded_rc_paths() click to toggle source
# File lib/fuzz/options.rb, line 129
def _loaded_rc_paths
  @loaded_rc_paths ||= []
end
_rc_paths() click to toggle source
# File lib/fuzz/options.rb, line 126
def _rc_paths
  @rc_paths ||= []
end