Flatten all zones

main
Micke Nordin 6 days ago
parent 2d5dea59cf
commit d7ebfc232a

@ -7,37 +7,53 @@ local log = require('plenary.log').new {
level = 'info', level = 'info',
} }
local telescope_knot = {} local _get_name = function(record)
local name = record.rtype .. " " .. record.name .. " " .. record.data
return name
end
local _filter_records = function(rec, records)
local r = {}
local record_name = rec.value
for _, record in ipairs(records) do
local name = _get_name(record)
if name == record_name then
r = { "ZONE", record.zone, "RTYPE", record.rtype, "NAME", record.name, "DATA", record.data, "TTL", record.ttl, "URL", record.url }
end
end
return r
end
local telescope_knot = {}
telescope_knot.zones = function(opts) telescope_knot.zones = function(opts)
local results = vim.json.decode(vim.fn.system("knotctl --json list")) local results = vim.json.decode(vim.fn.system("knotctl --json list"))
local records = {}
local entries = vim.tbl_map(function(zone) for _, zone in ipairs(results) do
return zone.name for _, record in ipairs(zone.records) do
end, results) if record then
record.zone = zone.name
table.insert(records, record)
end
end
end
local entries = vim.tbl_map(
function(record)
return _get_name(record)
end,
records
)
pickers.new(opts, { pickers.new(opts, {
dropdown = true, dropdown = true,
prompt_title = "Zones", prompt_title = "Records",
sorter = conf.generic_sorter(opts), sorter = conf.generic_sorter(opts),
finder = finders.new_table(entries), finder = finders.new_table(entries),
previewer = previewers.new_buffer_previewer({ previewer = previewers.new_buffer_previewer({
title = "Zone", title = "Record",
define_preview = function(self, entry) define_preview = function(self, entry)
local zone = {} local record = _filter_records(entry, records)
for _, z in ipairs(results) do vim.api.nvim_buf_set_lines(self.state.bufnr, 0, 0, false, record)
if z.name == entry.display then
zone = z
break
end
end
if zone then
local formatted_zone = vim.tbl_map(
function(record)
return record.rtype .. " " .. record.name .. " " .. record.data
end,
zone["records"])
vim.api.nvim_buf_set_lines(self.state.bufnr, 0, 0, false, formatted_zone)
end
end end
}), }),

Loading…
Cancel
Save