module DLDInternet::MixLib::Thor::No_Commands

Constants

LOG_LEVELS

Public Instance Methods

_expand(k,v,regex,rerun) click to toggle source
# File lib/dldinternet/mixlib/thor/no_commands.rb, line 70
def _expand(k,v,regex,rerun)
  matches = v.match(regex)
  if matches
    var = matches[1]
    if options[var]
      options[k]=v.gsub(/\%\(#{var}\)/,options[var]).gsub(/\%#{var}/,options[var])
    else
      rerun[var] = 1
    end
  end
end
abort!(msg) click to toggle source
# File lib/dldinternet/mixlib/thor/no_commands.rb, line 109
def abort!(msg)
  @logger.error msg
  exit -1
end
parse_options() click to toggle source
# File lib/dldinternet/mixlib/thor/no_commands.rb, line 28
def parse_options
  validate_options

  lcs = ::Logging::ColorScheme.new( 'compiler', :levels => {
      :trace => :blue,
      :debug => :cyan,
      :info  => :green,
      :step  => :green,
      :warn  => :yellow,
      :error => :red,
      :fatal => :red,
      :todo  => :purple,
  })
  scheme = lcs.scheme
  scheme['trace'] = "\e[38;5;33m"
  scheme['fatal'] = "\e[38;5;89m"
  scheme['todo']  = "\e[38;5;55m"
  lcs.scheme scheme
  @config         = @options.dup
  @config[:log_opts] = lambda{|mlll| {
      :pattern      => "%#{mlll}l: %m %g\n",
      :date_pattern => '%Y-%m-%d %H:%M:%S',
      :color_scheme => 'compiler',
      :trace        => (@config[:trace].nil? ? false : @config[:trace]),
      # [2014-06-30 Christo] DO NOT do this ... it needs to be a FixNum!!!!
      # If you want to do ::Logging.init first then fine ... go ahead :)
      # :level        => @config[:log_level],
  }
  }
  @logger = getLogger(@config)

  if @options[:inifile]
    @options[:inifile] = File.expand_path(@options[:inifile])
    unless File.exist?(@options[:inifile])
      raise "#{@options[:inifile]} not found!"
    end
    begin
      ini = ::IniFile.load(@options[:inifile])
      ini['global'].each{ |key,value|
        @options[key.to_s]=value
        ENV[key.to_s]=value
      }
      def _expand(k,v,regex,rerun)
        matches = v.match(regex)
        if matches
          var = matches[1]
          if options[var]
            options[k]=v.gsub(/\%\(#{var}\)/,options[var]).gsub(/\%#{var}/,options[var])
          else
            rerun[var] = 1
          end
        end
      end

      pending = nil
      rerun = {}
      begin
        pending = rerun
        rerun = {}
        options.to_hash.each{|k,v|
          if v.to_s.match(/\%/)
            _expand(k,v,%r'[^\\]\%\((\w+)\)', rerun)
            _expand(k,v,%r'[^\\]\%(\w+)',     rerun)
          end
        }
        # Should break out the first time that we make no progress!
      end while pending != rerun
    rescue ::IniFile::Error => e
      # noop
    rescue ::Exception => e
      @logger.error "#{e.class.name} #{e.message}"
      raise e
    end
  end

  if options[:verbose]
    @logger.info "Options:\n#{options.ai}"
  end

end
validate_options() click to toggle source
# File lib/dldinternet/mixlib/thor/no_commands.rb, line 16
def validate_options
  _options = options.dup
  if options[:log_level]
    log_level = options[:log_level].to_sym
    raise "Invalid log-level: #{log_level}" unless LOG_LEVELS.include?(log_level)
    _options[:log_level] = log_level
  else
    _options[:log_level] ||= :step
  end
  @options = _options
end