diff options
| author | ruki <[email protected]> | 2016-03-22 20:33:47 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-03-22 20:33:47 +0800 |
| commit | 54a4072a8c4fb163d58698ab4e575a5035a6233a (patch) | |
| tree | 7ad0af6a526843ec657ff2afe8b864b592ef0fcb | |
| parent | aca0257d26134ff95889acb419d49701fee4ec61 (diff) | |
add lua scripts for action
| -rw-r--r-- | xmake/actions/lua/scripts/cp.lua (renamed from xmake/core/platform/tools/cp.lua) | 17 | ||||
| -rw-r--r-- | xmake/actions/lua/scripts/echo.lua | 2 | ||||
| -rw-r--r-- | xmake/actions/lua/scripts/mkdir.lua (renamed from xmake/core/platform/tools/mkdir.lua) | 19 | ||||
| -rw-r--r-- | xmake/actions/lua/scripts/mv.lua (renamed from xmake/core/platform/tools/mv.lua) | 17 | ||||
| -rw-r--r-- | xmake/actions/lua/scripts/rm.lua (renamed from xmake/core/platform/tools/rm.lua) | 18 | ||||
| -rw-r--r-- | xmake/actions/lua/scripts/rmdir.lua (renamed from xmake/core/platform/tools/rmdir.lua) | 17 | ||||
| -rw-r--r-- | xmake/actions/lua/scripts/verbose.lua (renamed from xmake/core/platform/tools/verbose.lua) | 24 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 13 |
8 files changed, 35 insertions, 92 deletions
diff --git a/xmake/core/platform/tools/cp.lua b/xmake/actions/lua/scripts/cp.lua index c2914c6c5..ef11468bb 100644 --- a/xmake/core/platform/tools/cp.lua +++ b/xmake/actions/lua/scripts/cp.lua @@ -20,25 +20,14 @@ -- @file cp.lua -- --- define module: cp -local cp = cp or {} - --- load modules -local os = require("base/os") - --- the main function -function cp.main(self, ...) +-- main +function main(...) -- cp it local pathes = ... if pathes and table.getn(pathes) == 2 then - return os.cp(pathes[1], pathes[2]) + os.cp(pathes[1], pathes[2]) end - -- failed - return false - end --- return module: cp -return cp diff --git a/xmake/actions/lua/scripts/echo.lua b/xmake/actions/lua/scripts/echo.lua index 40165df2b..d6ce8ede0 100644 --- a/xmake/actions/lua/scripts/echo.lua +++ b/xmake/actions/lua/scripts/echo.lua @@ -20,7 +20,7 @@ -- @file echo.lua -- --- the main function +-- main function main(...) -- echo all diff --git a/xmake/core/platform/tools/mkdir.lua b/xmake/actions/lua/scripts/mkdir.lua index bf0983285..4d912c813 100644 --- a/xmake/core/platform/tools/mkdir.lua +++ b/xmake/actions/lua/scripts/mkdir.lua @@ -20,27 +20,14 @@ -- @file mkdir.lua -- --- define module: mkdir -local mkdir = mkdir or {} - --- load modules -local os = require("base/os") - --- the main function -function mkdir.main(self, ...) +-- main +function main(...) -- mkdir all for _, dir in ipairs(...) do if not os.exists(dir) then - if not os.mkdir(dir) then - return false - end + os.mkdir(dir) end end - - -- ok - return true end --- return module: mkdir -return mkdir diff --git a/xmake/core/platform/tools/mv.lua b/xmake/actions/lua/scripts/mv.lua index 41eae3cf1..a34d39458 100644 --- a/xmake/core/platform/tools/mv.lua +++ b/xmake/actions/lua/scripts/mv.lua @@ -20,24 +20,13 @@ -- @file mv.lua -- --- define module: mv -local mv = mv or {} - --- load modules -local os = require("base/os") - --- the main function -function mv.main(self, ...) +-- main +function mv.main(...) -- mv it local pathes = ... if pathes and table.getn(pathes) == 2 then - return os.mv(pathes[1], pathes[2]) + os.mv(pathes[1], pathes[2]) end - - -- failed - return false end --- return module: mv -return mv diff --git a/xmake/core/platform/tools/rm.lua b/xmake/actions/lua/scripts/rm.lua index 5db72c08e..dd7db8456 100644 --- a/xmake/core/platform/tools/rm.lua +++ b/xmake/actions/lua/scripts/rm.lua @@ -20,27 +20,15 @@ -- @file rm.lua -- --- define module: rm -local rm = rm or {} - --- load modules -local os = require("base/os") - --- the main function -function rm.main(self, ...) +-- main +function main(...) -- rm all for _, file_or_dir in ipairs(...) do if os.exists(file_or_dir) then - if not os.rm(file_or_dir) then - return false - end + os.rm(file_or_dir) end end - -- ok - return true end --- return module: rm -return rm diff --git a/xmake/core/platform/tools/rmdir.lua b/xmake/actions/lua/scripts/rmdir.lua index 9089453e3..17dc63f7e 100644 --- a/xmake/core/platform/tools/rmdir.lua +++ b/xmake/actions/lua/scripts/rmdir.lua @@ -20,27 +20,14 @@ -- @file rmdir.lua -- --- define module: rmdir -local rmdir = rmdir or {} - --- load modules -local os = require("base/os") - --- the main function +-- main function rmdir.main(self, ...) -- rmdir all for _, dir in ipairs(...) do if os.isdir(dir) then - if not os.rmdir(dir) then - return false - end + os.rmdir(dir) end end - -- ok - return true end - --- return module: rmdir -return rmdir diff --git a/xmake/core/platform/tools/verbose.lua b/xmake/actions/lua/scripts/verbose.lua index 2964ceb67..a9fb24a6e 100644 --- a/xmake/core/platform/tools/verbose.lua +++ b/xmake/actions/lua/scripts/verbose.lua @@ -19,30 +19,20 @@ -- @author ruki -- @file verbose.lua -- + +-- imports +import("core.base.option") - --- define module: verbose -local verbose = verbose or {} - --- load modules -local io = require("base/io") -local string = require("base/string") -local option = require("base/option") - --- the main function -function verbose.main(self, ...) +-- main +function main(...) -- verbose all if option.get("verbose") then for _, v in ipairs(...) do - io.write(string.format("%s ", v:decode())) + printf("%s ", v:decode()) end - io.write("\n") + print("") end - -- ok - return true end --- return module: verbose -return verbose diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index 1fedef80e..2dcc46233 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -217,6 +217,19 @@ function sandbox_os.isfile(filepath) return os.isfile(filepath) end +-- exists file or directory? +function sandbox_os.exists(file_or_dir) + + -- check + assert(file_or_dir) + + -- format it first + file_or_dir = vformat(file_or_dir) + + -- done + return os.exists(file_or_dir) +end + -- raise an exception and abort the current script function sandbox_os.raise(msg, ...) |
