From 8c6fcc182b457e9dfec4565f2b627ff89e330a74 Mon Sep 17 00:00:00 2001 From: v Date: Mon, 15 Jul 2024 22:04:08 +0200 Subject: [PATCH] fix options patching --- src/systemctl/VERSION | 2 +- src/systemctl/systemctl.lua | 34 +++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/systemctl/VERSION b/src/systemctl/VERSION index 373f8c6..72f9fa8 100644 --- a/src/systemctl/VERSION +++ b/src/systemctl/VERSION @@ -1 +1 @@ -0.2.3 \ No newline at end of file +0.2.4 \ No newline at end of file diff --git a/src/systemctl/systemctl.lua b/src/systemctl/systemctl.lua index d45d9bf..28ab831 100644 --- a/src/systemctl/systemctl.lua +++ b/src/systemctl/systemctl.lua @@ -237,28 +237,36 @@ end ---@param options SystemctlExecOptions ---@return table function systemctl.with_options(cachedOptions) + local function patch_options(options) + return util.merge_tables(cachedOptions, options, true) + end + ---@type Systemctl ---@diagnostic disable-next-line: missing-fields local systemctlWithOptions = {} function systemctlWithOptions.exec(options, ...) - options = util.merge_tables(cachedOptions, options, true) - return systemctl.exec(options, ...) + return systemctl.exec(patch_options(options), ...) end - local function wrap_with_options_patch(func) - return function(...) - local args = { ... } - args[#args] = util.merge_tables(cachedOptions, args[#args], true) + function systemctlWithOptions.install_service(sourceFile, serviceName, options) + return systemctl.install_service(sourceFile, serviceName, patch_options(options)) + end - return func(table.unpack(args)) - end + function systemctlWithOptions.start_service(serviceName, options) + return systemctl.start_service(serviceName, patch_options(options)) end - systemctlWithOptions.install_service = wrap_with_options_patch(systemctl.install_service) - systemctlWithOptions.start_service = wrap_with_options_patch(systemctl.start_service) - systemctlWithOptions.stop_service = wrap_with_options_patch(systemctl.stop_service) - systemctlWithOptions.remove_service = wrap_with_options_patch(systemctl.remove_service) - systemctlWithOptions.get_service_status = wrap_with_options_patch(systemctl.get_service_status) + function systemctlWithOptions.stop_service(serviceName, options) + return systemctl.stop_service(serviceName, patch_options(options)) + end + + function systemctlWithOptions.remove_service(serviceName, options) + return systemctl.remove_service(serviceName, patch_options(options)) + end + + function systemctlWithOptions.get_service_status(serviceName, options) + return systemctl.get_service_status(serviceName, patch_options(options)) + end return util.generate_safe_functions(systemctlWithOptions) end