Class: Enom::CLI

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

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/enom/cli.rb', line 6

def initialize
  # If the username and password are set elsewhere, they take precedence
  unless Enom::Client.username && Enom::Client.password
    file = File.expand_path("~/.enomconfig")
    if File.exists?(file)
      credentials = YAML.load(File.new(file))
      Enom::Client.username = credentials["username"]
      Enom::Client.password = credentials["password"]
    else
      raise InvalidCredentials, "Please provide a username/password as arguments create a config file with credentials in ~/.enomconfig"
    end
  end
end

Instance Method Details

#commandsObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/enom/cli.rb', line 35

def commands
  {
    "list"     => Enom::Commands::ListDomains,
    "check"    => Enom::Commands::CheckDomain,
    "register" => Enom::Commands::RegisterDomain,
    "renew"    => Enom::Commands::RenewDomain,
    "describe" => Enom::Commands::DescribeDomain,
    "transfer" => Enom::Commands::TransferDomain
  }
end

#execute(command_name, args, options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/enom/cli.rb', line 20

def execute(command_name, args, options={})
  command = commands[command_name]
  if command
    begin
      command.new.execute(args, options)
    rescue Enom::Error => e
      puts "An error occurred: #{e.message}"
    rescue RuntimeError => e
      puts "An error occurred: #{e.message}"
    end
  else
    raise CommandNotFound, "Unknown command: #{command_name}"
  end
end