class DNSCheck::CLI

Attributes

args[R]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/dns-check/cli.rb, line 15
def initialize
  super
  @args = ARGV
end

Public Instance Methods

run() click to toggle source
# File lib/dns-check/cli.rb, line 20
def run
  config.merge!(parse_options)
  DNSCheck::Node.start
end

Private Instance Methods

config() click to toggle source
# File lib/dns-check/cli.rb, line 27
def config
  DNSCheck.config
end
parse_options() click to toggle source
# File lib/dns-check/cli.rb, line 38
def parse_options
  opts = {}

  parser = OptionParser.new do |o|
    o.separator ''
    o.separator 'Options:'

    o.on '-l', '--location   [name]', String, 'Location can either be a country or city' do |loc|
      opts[:location] = loc
    end

    o.on '-t', '--timeout    [sec]', Integer, 'DNS Query timeout (Default: 5s)' do |sec|
      opts[:timeout] = sec
    end

    o.on '--records    [size]', Integer, 'Number of nameservers to select (default: 10)' do |size|
      opts[:size] = size
    end

    o.on '--sep        [sep]', String, 'Set separator (default: |)' do |sep|
      opts[:sep] = sep
    end

    o.on '--no-recursion', 'Disable recursion' do
      opts[:no_recursion] = true
    end

    o.on '--show-ns', 'Show nameservers' do
      opts[:show_ns] = true
    end

    o.on '--update', 'Perform indice update' do
      update!
    end
    
    o.on '--debug' do
      $DEBUG = true
    end

    o.on_tail '-v', '--version', 'Show version' do
      puts DNSCheck::VERSION
      exit 0
    end
  end

  parser.banner = 'Usage: dns-check [options] [domain]'
  parser.on_tail '-h', '-?', '--help', 'Show this message' do
    puts parser
    exit 0
  end

  parser.parse!(@args)

  if @args.empty?
    puts parser
    exit 0
  end

  opts[:hostname] = @args[0]
  opts
end
update!() click to toggle source
# File lib/dns-check/cli.rb, line 31
def update!
  DNSCheck.indice_location = config[:indice_location]
  DNSCheck.indice_store    = config[:indice_store]
  DNSCheck.update!
  exit 0
end