summaryrefslogtreecommitdiff
path: root/xmake/actions/create/main.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2026-03-03 23:42:58 +0800
committerruki <[email protected]>2026-03-03 23:42:58 +0800
commit5abb591b562a07ef59213cc1ddc8b74dd181f7ac (patch)
treeec59101e7cf6b986aa3de562f4d2efcc98078963 /xmake/actions/create/main.lua
parentf23220b1abbb51882f1912533b397f2f2d38b66b (diff)
get templates from xmake-repo
Diffstat (limited to 'xmake/actions/create/main.lua')
-rw-r--r--xmake/actions/create/main.lua86
1 files changed, 83 insertions, 3 deletions
diff --git a/xmake/actions/create/main.lua b/xmake/actions/create/main.lua
index fc75e06a4..72b69f3b2 100644
--- a/xmake/actions/create/main.lua
+++ b/xmake/actions/create/main.lua
@@ -63,7 +63,13 @@ function _get_targetname()
end
-- list all supported templates for each language
+--
+-- output is in tree format:
+-- <source>
+-- <language>
+-- <template>
function _list_templates(lang_filter)
+ local rootinfos = template.rootinfos()
local languages = template.languages()
if lang_filter then
_validate_template_component("language", lang_filter)
@@ -72,15 +78,89 @@ function _list_templates(lang_filter)
end
languages = {lang_filter}
end
+
+ -- map a template directory to its root meta (repo/global/builtin)
+ local rootinfo_of = function (dir)
+ if not dir then
+ return
+ end
+ dir = path.absolute(dir)
+ for _, info in ipairs(rootinfos) do
+ local rootdir = path.absolute(info.dir)
+ if dir == rootdir or dir:startswith(rootdir .. path.sep()) then
+ return info
+ end
+ end
+ end
+
+ local sourcekey_of = function (info)
+ if not info then
+ return "unknown"
+ end
+ if info.kind == "repo" then
+ return "repo:" .. info.name
+ end
+ return info.kind or "unknown"
+ end
+
+ local groups = {}
for _, lang in ipairs(languages) do
- cprint("${bright}%s${reset}", lang)
local templates = template.templates(lang)
if templates and #templates > 0 then
for _, name in ipairs(templates) do
- cprint(" - %s", name)
+ local sourcedir = template.templatedir(lang, name)
+ local info = rootinfo_of(sourcedir)
+ local key = sourcekey_of(info)
+ local group = groups[key]
+ if not group then
+ group = {info = info, langs = {}}
+ groups[key] = group
+ end
+ group.langs[lang] = group.langs[lang] or {}
+ table.insert(group.langs[lang], name)
+ end
+ end
+ end
+
+ local groupkeys = {}
+ local inserted = {}
+ for _, info in ipairs(rootinfos) do
+ local key = sourcekey_of(info)
+ if groups[key] and not inserted[key] then
+ table.insert(groupkeys, key)
+ inserted[key] = true
+ end
+ end
+ if groups["unknown"] and not inserted["unknown"] then
+ table.insert(groupkeys, "unknown")
+ inserted["unknown"] = true
+ end
+
+ for _, key in ipairs(groupkeys) do
+ local group = groups[key]
+ if group then
+ local info = group.info
+ if info and info.kind == "repo" then
+ local branch = info.branch and (" " .. info.branch) or ""
+ cprint("${bright}%s${reset}: %s%s", info.name, info.url or "", branch)
+ else
+ cprint("${bright}%s${reset}", (info and info.kind) or "unknown")
+ end
+ local langs = {}
+ for lang, _ in pairs(group.langs) do
+ table.insert(langs, lang)
+ end
+ table.sort(langs)
+ for _, lang in ipairs(langs) do
+ cprint(" ${bright}%s${reset}", lang)
+ local templates = group.langs[lang]
+ table.sort(templates)
+ for _, name in ipairs(templates) do
+ print(" - %s", name)
+ end
end
+ print("")
end
- print("")
end
end