summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-12-28 23:33:02 +0800
committerruki <[email protected]>2025-12-28 23:35:33 +0800
commit27213c369422c1e07d62a70cb652fe6b8bf74af6 (patch)
tree956fa975767361de045c8c2b109505221c6fc760
parent6986387d96dccf24e25cbc6895bfcc3c3df6b030 (diff)
support more json list
-rw-r--r--xmake/plugins/show/lists/packages.lua1
-rw-r--r--xmake/plugins/show/lists/policies.lua13
-rw-r--r--xmake/plugins/show/lists/toolchains.lua12
3 files changed, 24 insertions, 2 deletions
diff --git a/xmake/plugins/show/lists/packages.lua b/xmake/plugins/show/lists/packages.lua
index 2677b70c5..5c03bdd66 100644
--- a/xmake/plugins/show/lists/packages.lua
+++ b/xmake/plugins/show/lists/packages.lua
@@ -21,7 +21,6 @@
-- imports
import("core.project.config")
import("private.action.require.list", { alias = "show_packages" })
-import(".showlist")
-- show all packages
function main()
diff --git a/xmake/plugins/show/lists/policies.lua b/xmake/plugins/show/lists/policies.lua
index 7f5c650cc..376e97427 100644
--- a/xmake/plugins/show/lists/policies.lua
+++ b/xmake/plugins/show/lists/policies.lua
@@ -20,11 +20,22 @@
-- imports
import("core.project.policy")
+import("core.base.json")
+import("core.base.option")
-- show all policies
function main()
- local width = 45
local policies = policy.policies()
+ if option.get("json") then
+ local list = {}
+ for name, policy in table.orderpairs(policies) do
+ table.insert(list, {name = name, description = policy.description, default = policy.default or "false"})
+ end
+ print(json.encode(list))
+ return
+ end
+
+ local width = 45
for name, policy in table.orderpairs(policies) do
cprint("${color.dump.string}%s${clear}%s%s", name, (" "):rep(width - #name), policy["description"])
cprint("%s${bright}%s", (" "):rep(width), policy["default"] or "false")
diff --git a/xmake/plugins/show/lists/toolchains.lua b/xmake/plugins/show/lists/toolchains.lua
index 77b048e5c..2ed8bc52d 100644
--- a/xmake/plugins/show/lists/toolchains.lua
+++ b/xmake/plugins/show/lists/toolchains.lua
@@ -21,6 +21,8 @@
-- imports
import("core.tool.toolchain")
import("core.base.text")
+import("core.base.json")
+import("core.base.option")
import("core.project.config")
import("core.project.project")
@@ -28,6 +30,16 @@ import("core.project.project")
function main()
config.load()
+ if option.get("json") then
+ local list = {}
+ for _, name in ipairs(toolchain.list()) do
+ local t = os.isfile(os.projectfile()) and project.toolchain(name) or toolchain.load(name)
+ table.insert(list, {name = name, description = t:get("description")})
+ end
+ print(json.encode(list))
+ return
+ end
+
local tbl = {align = 'l', sep = " "}
for _, name in ipairs(toolchain.list()) do
local t = os.isfile(os.projectfile()) and project.toolchain(name) or toolchain.load(name)