From 95dcdbaebbf3819cd0a601ba87d25e1659e382df Mon Sep 17 00:00:00 2001 From: michael Date: Thu, 28 Aug 2025 17:34:36 +0200 Subject: [PATCH] feat(integration): add universal merkwerk binary detection - Check development binary (./bin/merkwerk) - Check installed binary (/usr/local/bin/merkwerk) - Fallback to PATH lookup (command -v merkwerk) - Proper error handling for missing binary Related to DAW/furt#94 --- integrations/lua-api.lua | 43 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/integrations/lua-api.lua b/integrations/lua-api.lua index 0d15243..b543bce 100644 --- a/integrations/lua-api.lua +++ b/integrations/lua-api.lua @@ -10,10 +10,51 @@ local cache = { ttl = 300 -- 5 minutes default TTL } +-- Find merkwerk binary using universal detection pattern +local function find_merkwerk_binary() + -- Check development binary + local dev_handle = io.popen("test -x './bin/merkwerk' && echo './bin/merkwerk' 2>/dev/null") + if dev_handle then + local dev_result = dev_handle:read("*line") + dev_handle:close() + if dev_result and dev_result ~= "" then + return dev_result + end + end + + -- Check installed binary + local inst_handle = io.popen("test -x '/usr/local/bin/merkwerk' && echo '/usr/local/bin/merkwerk' 2>/dev/null") + if inst_handle then + local inst_result = inst_handle:read("*line") + inst_handle:close() + if inst_result and inst_result ~= "" then + return inst_result + end + end + + -- Check PATH + local path_handle = io.popen("command -v merkwerk 2>/dev/null") + if path_handle then + local path_result = path_handle:read("*line") + path_handle:close() + if path_result and path_result ~= "" then + return "merkwerk" + end + end + + return nil +end + -- Execute merkwerk command and return result local function execute_merkwerk(args) args = args or "info --json" - local command = "./tools/merkwerk/bin/merkwerk " .. args .. " 2>/dev/null" + + local merkwerk_cmd = find_merkwerk_binary() + if not merkwerk_cmd then + return nil, "merkwerk binary not found" + end + + local command = merkwerk_cmd .. " " .. args .. " 2>/dev/null" local handle = io.popen(command) if not handle then