Class: CheckDomain::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/checkdomain/cli.rb

Class Method Summary collapse

Class Method Details

.execute(stdout, arguments = []) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/checkdomain/cli.rb', line 5

def self.execute(stdout, arguments=[])
  options = {
    :domains     => ARGV[0].to_s.strip.empty? ? nil : ARGV
  }
  mandatory_options = %w( domains )

  parser = OptionParser.new do |opts|
    opts.banner = <<-BANNER.gsub(/^          /,'')
      Easily check a domain's availability from the commandline.

      Usage: #{File.basename($0)} domain [domain2 domain3 etc.] [options]

      Options are:
    BANNER
    opts.separator ""
    opts.on("-h", "--help",
            "Show this help message.") { stdout.puts opts; exit }
    opts.parse!(arguments)

    if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
      stdout.puts opts; exit
    end
  end

  path = options[:path]

  search = CheckDomain::Search.new
  search.run(options[:domains])     
end