summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérôme Leclercq <[email protected]>2022-07-05 18:09:21 +0200
committerGitHub <[email protected]>2022-07-05 18:09:21 +0200
commitc9739dbe0c38a8be552e8f6a79cc4a9820e81630 (patch)
treed90edb87e07934f412439bdf69e3f5d1912f58bd
parent6e7f78a7ba89f868cd97e9ebd1362970e52c0bf6 (diff)
improve code
-rw-r--r--xmake/actions/run/main.lua23
1 files changed, 16 insertions, 7 deletions
diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua
index 841df4780..3e1a9de76 100644
--- a/xmake/actions/run/main.lua
+++ b/xmake/actions/run/main.lua
@@ -94,6 +94,20 @@ function _add_target_pkgenvs(target, targets_added)
end
end
+-- find target names matching a specific name
+function _find_matching_target_names(targetname)
+ targetname = targetname:lower()
+ local matching_targetnames = {}
+ for _, target in ipairs(project.ordertargets()) do
+ if target:name():lower():find(targetname) then
+ table.insert(matching_targetnames, target:name())
+ end
+ end
+
+ table.sort(matching_targetnames)
+ return matching_targetnames
+end
+
-- run the given target
function _run(target)
@@ -151,16 +165,11 @@ function _check_targets(targetname, group_pattern)
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 possible_targetnames =_find_matching_target_names(targetname)
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 - ')
+ err = err .. "\nlist of valid target names close to your input:\n - " .. table.concat(possible_targetnames, '\n - ')
end
raise(err)