summaryrefslogtreecommitdiff
path: root/xmake/plugins/lua/xmake.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2017-05-16 13:06:35 +0800
committerruki <[email protected]>2017-05-16 13:06:35 +0800
commitcd09a4bc9a4a780cd857fff34444a00583de42ab (patch)
tree3207493d3c77f1f17f1049ef25ae8d5b26892cc3 /xmake/plugins/lua/xmake.lua
parentcbfbc9762e007654055ba3ec411de8cfc28e1bd1 (diff)
support args to run a single lua command
Diffstat (limited to 'xmake/plugins/lua/xmake.lua')
-rw-r--r--xmake/plugins/lua/xmake.lua29
1 files changed, 14 insertions, 15 deletions
diff --git a/xmake/plugins/lua/xmake.lua b/xmake/plugins/lua/xmake.lua
index 0b867d966..354477e16 100644
--- a/xmake/plugins/lua/xmake.lua
+++ b/xmake/plugins/lua/xmake.lua
@@ -46,32 +46,30 @@ task("lua")
end
-- run command?
- local cmd = option.get("command")
- local name = nil
- if cmd then
+ local script = option.get("script")
+ if option.get("command") and script then
local tmpfile = os.tmpfile() .. ".lua"
- io.writefile(tmpfile, "function main()\n" .. cmd .. "\nend")
- name = tmpfile
+ io.writefile(tmpfile, "function main(...)\n" .. script .. "\nend")
+ script = tmpfile
end
- -- get script name
- name = name or option.get("script")
- if name then
+ -- get script
+ if script then
-- import and run script
- if os.isfile(name) then
+ if os.isfile(script) then
-- run the given lua script file (xmake lua /tmp/script.lua)
- import(path.basename(name), {rootdir = path.directory(name)})(unpack(option.get("arguments") or {}))
+ import(path.basename(script), {rootdir = path.directory(script)})(unpack(option.get("arguments") or {}))
- elseif os.isfile(path.join(os.scriptdir(), "scripts", name .. ".lua")) then
+ elseif os.isfile(path.join(os.scriptdir(), "scripts", script .. ".lua")) then
-- run builtin lua script (xmake lua echo "hello xmake")
- import("scripts." .. name)(unpack(option.get("arguments") or {}))
+ import("scripts." .. script)(unpack(option.get("arguments") or {}))
else
-- run modules (xmake lua core.xxx.xxx)
- import(name)(unpack(option.get("arguments") or {}))
+ import(script)(unpack(option.get("arguments") or {}))
end
else
-- enter interactive mode
@@ -96,13 +94,14 @@ task("lua")
{'l', "list", "k", nil, "List all scripts." }
, {nil, "root", "k", nil, "Allow to run script as root." }
- , {'c', "command", "kv", nil, "Run command" }
+ , {'c', "command", "k", nil, "Run script as command" }
, {nil, "script", "v", nil, "Run the given lua script name, file or module and enter interactive mode if no given script.",
".e.g",
" - xmake lua (enter interactive mode)",
" - xmake lua /tmp/script.lua",
" - xmake lua echo 'hello xmake'",
- " - xmake lua core.xxx.xxx" }
+ " - xmake lua core.xxx.xxx",
+ " - xmake lua -c 'print(...)' hello xmake!" }
, {nil, "arguments", "vs", nil, "The script arguments." }
}
}