Sha256: e960b97040efab3c5832d1177b77b585bff962a543c0fbc8c34bb9ac3d7236fb

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

module PowerDNS
  module DB
    module CLI
      class Record < Thor
        include Thor::Actions

        desc 'create <domain> <name> <type> <content> [prio] [ttl] [auth]', 'Create record.'
        def create(domain, name, type, content, prio = 0, ttl = 38400, auth = 'true')
          d = DB::Domain.where(name: domain).first!

          d.records.create! \
            name: name,
            type: type,
            content: content,
            prio: prio,
            ttl: ttl,
            auth: auth == 'true'
        end

        desc 'list <domain> [type]', 'List records of domain.'
        def list(domain, type = nil)
          d = DB::Domain.where(name: domain).first!

          h = [:name, :type, :prio, :content, :ttl, :auth]

          r = type.nil? ? d.records : d.records.where(type: type)
          r = r.order(*h[0..1]).pluck(*h)

          t = Terminal::Table.new(headings: h, rows: r)
          t.align_column(0, :right)

          puts t
        end

        desc 'remove <domain> <name> <type> [content] [prio]', 'Remove record.'
        option :yes, type: :boolean
        def remove(domain, name, type, content = nil, prio = nil)
          d = DB::Domain.where(name: domain).first!

          h = { name: name, type: type }
          h[:content] = content unless content.nil?
          h[:prio] = prio unless prio.nil?

          r = d.records.where(h)
          c = r.size

          if c > 0
            r.destroy_all if options[:yes] || yes?("Delete #{c} records?")
          else
            say("No records found.")
          end
        end
      end

      class Main
        desc 'record <action> [args..]', 'Record actions.'
        subcommand 'record', Record
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
powerdns_db_cli-0.0.9 lib/powerdns_db_cli/cli/record.rb