Class: Esgob::CLI
- Inherits:
-
Thor
- Object
- Thor
- Esgob::CLI
- Defined in:
- lib/esgob/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #account ⇒ Object
- #config ⇒ Object
- #domains ⇒ Object
- #slaves ⇒ Object
- #slaves_add(domain, masterip) ⇒ Object
- #slaves_delete(domain) ⇒ Object
- #slaves_sync(filename, masterip) ⇒ Object
- #slaves_transfer(domain) ⇒ Object
- #slaves_update(domain, masterip) ⇒ Object
- #soacheck(domain) ⇒ Object
- #version ⇒ Object
Class Method Details
.start(args = ARGV, config = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/esgob/cli.rb', line 19 def self.start(args = ARGV, config = {}) config[:shell] ||= Thor::Base.shell.new begin super(args, config) rescue Esgob::ServerError => err $stderr.puts config[:shell].set_color("=> Error: #{err.} [#{err.code}]", :red, :bold) rescue Esgob::UnconfiguredError => err $stderr.puts config[:shell].set_color("=> Error: #{err.}", :red, :bold) $stderr.puts "Use the 'esgob config' command to create a configuration file." end end |
Instance Method Details
#account ⇒ Object
41 42 43 44 45 |
# File 'lib/esgob/cli.rb', line 41 def account client.accounts_get.each_pair do |k, v| say sprintf("%8s: %s\n", k, v) end end |
#config ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/esgob/cli.rb', line 32 def config config = Esgob::Config.new config.account = ask("What is your Esgob account name?") config.key = ask("What is your Esgob key?") config.save say "Configuration written to #{config.filepath}" end |
#domains ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/esgob/cli.rb', line 48 def domains print_table( [['Domain', 'Type']] + [['------', '----']] + client.domains_list.map { |h| [h[:domain], h[:type]] } ) end |
#slaves ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/esgob/cli.rb', line 57 def slaves print_table( [['Domain', 'Master IP']] + [['------', '---------']] + client.domains_slaves_list.to_a ) end |
#slaves_add(domain, masterip) ⇒ Object
66 67 68 69 70 |
# File 'lib/esgob/cli.rb', line 66 def slaves_add(domain, masterip) check_action do client.domains_slaves_add(domain, masterip) end end |
#slaves_delete(domain) ⇒ Object
73 74 75 76 77 |
# File 'lib/esgob/cli.rb', line 73 def slaves_delete(domain) check_action do client.domains_slaves_delete(domain) end end |
#slaves_sync(filename, masterip) ⇒ Object
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/esgob/cli.rb', line 97 def slaves_sync(filename, masterip) domains = [] File.foreach(filename) do |line| domains << line.strip.split(/\s+/).first end check_action do client.domains_slaves_sync(domains, masterip) end end |
#slaves_transfer(domain) ⇒ Object
81 82 83 84 85 |
# File 'lib/esgob/cli.rb', line 81 def slaves_transfer(domain) check_action do client.domains_slaves_forcetransfer(domain) end end |
#slaves_update(domain, masterip) ⇒ Object
89 90 91 92 93 |
# File 'lib/esgob/cli.rb', line 89 def slaves_update(domain, masterip) check_action do client.domains_slaves_updatemasterip(domain, masterip) end end |
#soacheck(domain) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/esgob/cli.rb', line 110 def soacheck(domain) response = client.domains_tools_soacheck(domain) print_table( [['Identifier', 'Type', 'Country', 'SOA', 'Response']] + [['----------', '----', '-------', '---', '--------']] + response[:responses][:masters].map do |node| [node[:ip], "master", '', node[:soa], node[:response]] end + response[:responses][:anycastnodes].map do |node| [node[:ref], 'anycast', node[:country], node[:soa], node[:response]] end ) end |