From 6e7f78a7ba89f868cd97e9ebd1362970e52c0bf6 Mon Sep 17 00:00:00 2001 From: Jérôme Leclercq Date: Tue, 5 Jul 2022 12:56:21 +0200 Subject: xmake run: Improve error message when target doesn't exist --- xmake/actions/run/main.lua | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua index 6daae3076..841df4780 100644 --- a/xmake/actions/run/main.lua +++ b/xmake/actions/run/main.lua @@ -148,7 +148,24 @@ function _check_targets(targetname, group_pattern) -- get targets local targets = {} if targetname then - local target = assert(project.target(targetname), "%s not found!", targetname) + local target = project.target(targetname) + if not target then + -- check if the name is part of other target to help + local possible_targetnames = {} + for _, target in ipairs(project.ordertargets()) do + if target:name():lower():find(targetname:lower()) then + table.insert(possible_targetnames, target:name()) + end + end + + local err = targetname .. " is not a valid target name for this project" + if #possible_targetnames > 0 then + err = err .. "\ndid you mean:\n - " .. table.concat(possible_targetnames, '\n - ') + end + + raise(err) + end + table.insert(targets, target) else for _, target in ipairs(project.ordertargets()) do -- cgit v1.3.1