Sha256: 955621732802a53f6c72c802cc7da0a60cc92f271a0cb64c8cfc1db20cfb3cdd

Contents?: true

Size: 1.65 KB

Versions: 3

Compression:

Stored size: 1.65 KB

Contents

module WWMD

  class WWMDConfig#:nodoc:
    # for backward compat
    def self.load_config(file); WWMD::load_config(file); end
    def self.parse_opts(args); WWMD::parse_opts(args); end
  end

  def load_config(file)
    begin
      config = YAML.load_file(file)
    rescue => e
      putw "config file not found #{file}"
      putw e.inspect
      exit
    end
    return config
  end

  def parse_opts(args)
    inopts = Hash.new
    inopts[:max_redirects] = 10
    inopts[:timeout] = 30
    inopts[:scrape_warn] = false
    opts = OptionParser.new do |opts|
    # set defaults
      opts.on("-p", "--password PASSWORD", "Password")     { |v| inopts[:password] = v }
      opts.on("-u", "--username USERNAME", "Username")     { |v| inopts[:username] = v }
      opts.on("--header_file HEADER_FILE","Header file")   { |v| inopts[:header_file] = v }
      opts.on("--base_url BASE_URL","Base url")            { |v| inopts[:base_url] = v }
      opts.on("--use_proxy PROXY_URL", "Use proxy at url") do |v|
        ENV['HTTP_PROXY'] = "http://" + v.to_s
        inopts[:use_proxy] = true
        inopts[:proxy_url] = v
      end
      opts.on("--no_proxy","do not use proxy") do |v|
        inopts[:use_proxy] = false
        inopts[:proxy_url] = nil
      end
      opts.on("--use_auth","login before getting url")     { |v| inopts[:use_auth] = true }
      opts.on("--no_auth","no login before getting url")   { |v| inopts[:use_auth] = false }
      opts.on("--debug","debugging really doesn't work")   { |v| inopts[:debug] = true }
      opts.on_tail("-h", "--help", "Show this message") do
        puts opts
        exit
      end
    end
    opts.parse!(args)
    return inopts
  end

end

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
iZsh-wwmd-0.2.19 lib/wwmd/wwmd_config.rb
miketracy-wwmd-0.2.19 lib/wwmd/wwmd_config.rb
wwmd-0.2.20.3 lib/wwmd/wwmd_config.rb