Class: Enom::CLI
- Inherits:
-
Object
- Object
- Enom::CLI
- Defined in:
- lib/enom/cli.rb
Instance Method Summary collapse
- #commands ⇒ Object
- #execute(command_name, args, options = {}) ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
Constructor Details
#initialize ⇒ CLI
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.("~/.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
#commands ⇒ Object
35 36 37 38 39 40 41 42 43 |
# 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 } 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, ={}) command = commands[command_name] if command begin command.new.execute(args, ) rescue Enom::Error => e puts "An error occurred: #{e.}" rescue RuntimeError => e puts "An error occurred: #{e.}" end else raise CommandNotFound, "Unknown command: #{command_name}" end end |