Class: DLDInternet::DOctl::Compute::Domain::Command

Inherits:
Thor::Command
  • Object
show all
Defined in:
lib/dldinternet/doctl/compute/domain/command.rb

Instance Method Summary collapse

Instance Method Details

#create(domain) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/dldinternet/doctl/compute/domain/command.rb', line 66

def create(domain)
  formats = Hashie::Mash.new({
                                 Domain: [ :name, '%-16s', :to_s ],
                                 TTL: [ :ttl, '%-6s', :to_i ],
                             })
  format_names = options[:format_string].split(/,/)
  format_templ = format_names.map { |name| formats[name][1] }.join('')

  @header = -> { sprintf(format_templ, *format_names) }
  @format = ->(o) {
    # h = Hashie::Mash.new(hash_it(o))
    sprintf(format_templ, *(format_names.map{ |n|
      if o.respond_to?(formats[n][0])
        o.send(formats[n][0]).send(formats[n][2])
      else
        $stderr.write "#{n} not in #{o.class.name}::#{hash_it(o)}\n"
        ''
      end
    })) }
  command_pre(domain)
  command_out(DLDInternet::DOctl::API::Compute::Domain::Create.new(options, @logger).CreateDomain(domain, options[:ip_address]))
  0
end

#delete(domain) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/dldinternet/doctl/compute/domain/command.rb', line 91

def delete(domain)
  @header = -> {  }
  @format = ->(o) { o.ai }
  command_pre(domain)
  command_out(DLDInternet::DOctl::API::Compute::Domain::Delete.new(options, @logger).DeleteDomain(domain))
  0
end

#get(domain) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/dldinternet/doctl/compute/domain/command.rb', line 38

def get(domain)
  formats = Hashie::Mash.new({
                                 Domain: [ :name, '%-16s', :to_s ],
                                 TTL: [ :ttl, '%-6s', :to_i ],
                             })
  format_names = options[:format_string].split(/,/)
  format_templ = format_names.map { |name| formats[name][1] }.join('')

  @header = -> { sprintf(format_templ, *format_names) }
  @format = ->(o) {
    # h = Hashie::Mash.new(hash_it(o))
    sprintf(format_templ, *(format_names.map{ |n|
      if o.respond_to?(formats[n][0])
        o.send(formats[n][0]).send(formats[n][2])
      else
        $stderr.write "#{n} not in #{o.class.name}::#{hash_it(o)}\n"
        ''
      end
    })) }
  command_pre(domain)
  command_out(DLDInternet::DOctl::API::Compute::Domain::Get.new(options, @logger).GetDomain(domain))
  0
end

#listObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dldinternet/doctl/compute/domain/command.rb', line 17

def list()
  command_pre
  res = DLDInternet::DOctl::API::Compute::Domain::List.new(options, @logger).GetDomainList()
  @header = -> { sprintf('%-17s%s', 'Domain', 'TTL') }
  @format = ->(obj) { sprintf('%-17s%s', obj[:name], obj[:ttl] ) }
  command_out(res)
  # case options[:format]
  # when /text|none/
  #   output sprintf('%-17s%s', 'Domain', 'TTL')
  #   res.each do |obj|
  #     output sprintf('%-17s%s', obj[:name], obj[:ttl] )
  #   end
  # else
  #   output res
  # end
  0
end