From 3cfc0006ba9b782d8f9a78de88affd395bd5b209 Mon Sep 17 00:00:00 2001 From: Fabrizio Damicelli Date: Sat, 27 Apr 2024 16:04:10 +0200 Subject: [PATCH] fix: simplify parse_opts with vim.tbl_deep_extend --- lua/cronex/config.lua | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/lua/cronex/config.lua b/lua/cronex/config.lua index a4a3211..f2d9cc0 100644 --- a/lua/cronex/config.lua +++ b/lua/cronex/config.lua @@ -17,31 +17,24 @@ local defaults = { } M.parse_opts = function(opts) - local user = vim.F.if_nil(opts, {}) - - -- Set first level keys, otherwise user.* will fail - for k, v in pairs(defaults) do - user[k] = vim.F.if_nil(user[k], v) - end + opts = vim.tbl_deep_extend("force", defaults, opts) local extract = function() - local extract = user.extractor.extract or defaults.extractor.extract - local cron_from_line = user.extractor.cron_from_line or defaults.extractor.cron_from_line - return extract(cron_from_line) + return opts.extractor.extract(opts.extractor.cron_from_line) end local explain = function(cron) - local cmd = user.explainer.cmd or defaults.explainer.cmd - local args = user.explainer.args or defaults.explainer.args + local cmd = opts.explainer.cmd + local args = opts.explainer.args local full_cmd = vim.tbl_flatten({ cmd, args }) return require("cronex.explain").explain(full_cmd, cron) end return { - file_patterns = user.file_patterns or defaults.file_patterns, + file_patterns = opts.file_patterns, extract = extract, explain = explain, - format = user.format or defaults.format, + format = opts.format, } end