diff options
| author | ruki <[email protected]> | 2016-06-09 20:27:48 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-06-09 20:27:48 +0800 |
| commit | cb9ce25dd0e7669189124a89bf6171190707b13e (patch) | |
| tree | 52a7953866430eb2c85eba180140c7195e26ac28 /xmake/plugins | |
| parent | 2429c51cf05dd13bc481704ad0a59e1bcef03ade (diff) | |
improve the macro plugin
Diffstat (limited to 'xmake/plugins')
| -rwxr-xr-x | xmake/plugins/macro/main.lua | 68 | ||||
| -rwxr-xr-x | xmake/plugins/macro/xmake.lua | 11 |
2 files changed, 67 insertions, 12 deletions
diff --git a/xmake/plugins/macro/main.lua b/xmake/plugins/macro/main.lua index b83b156b4..46c5e91aa 100755 --- a/xmake/plugins/macro/main.lua +++ b/xmake/plugins/macro/main.lua @@ -113,6 +113,13 @@ function _show(macroname) end end +-- clear all macros +function _clear() + + -- clear all + os.rm(path.join(config.directory(), "macros")) +end + -- delete macro function _delete(macroname) @@ -132,21 +139,61 @@ end -- import macro function _import(macrofile, macroname) - -- import it - os.cp(macrofile, _wfile(macroname)) + -- import all macros + if os.isdir(macrofile) then - -- trace - print("import macro(%s) ok!", macroname) + -- the macro directory + local macrodir = macrofile + local macrofiles = os.match(path.join(macrodir, "*.lua")) + for _, macrofile in ipairs(macrofiles) do + + -- the macro name + macroname = path.basename(macrofile) + + -- import it + os.cp(macrofile, _wfile(macroname)) + + -- trace + print("import macro(%s) ok!", macroname) + end + else + + -- import it + os.cp(macrofile, _wfile(macroname)) + + -- trace + print("import macro(%s) ok!", macroname) + end end -- export macro function _export(macrofile, macroname) - -- export it - os.cp(_rfile(macroname), macrofile) + -- export all macros + if os.isdir(macrofile) then - -- trace - print("export macro(%s) ok!", macroname) + -- the output directory + local outputdir = macrofile + + -- export all macros + for _, dir in ipairs(_directories()) do + local macrofiles = os.match(path.join(dir, "*.lua")) + for _, macrofile in ipairs(macrofiles) do + + -- export it + os.cp(macrofile, outputdir) + + -- trace + print("export macro(%s) ok!", path.basename(macrofile)) + end + end + else + -- export it + os.cp(_rfile(macroname), macrofile) + + -- trace + print("export macro(%s) ok!", macroname) + end end -- begin to record macro @@ -261,6 +308,11 @@ function main() _show(option.get("name")) + -- clear macro + elseif option.get("clear") then + + _clear() + -- delete macro elseif option.get("delete") then diff --git a/xmake/plugins/macro/xmake.lua b/xmake/plugins/macro/xmake.lua index f28c5b49f..4b6fd5ccd 100755 --- a/xmake/plugins/macro/xmake.lua +++ b/xmake/plugins/macro/xmake.lua @@ -57,13 +57,16 @@ task("macro") , {nil, "show", "k", nil, "Show the content of the given macro." } , {'l', "list", "k", nil, "List all macros." } , {'d', "delete", "k", nil, "Delete the given macro." } + , {'c', "clear", "k", nil, "Clear the all macros." } , {} - , {nil, "import", "kv", nil, "Import the given macro file." + , {nil, "import", "kv", nil, "Import the given macro file or directory." , ".e.g" - , " xmake macro --import=/xxx/macro.lua test" } - , {nil, "export", "kv", nil, "Export the given macro to file." + , " xmake macro --import=/xxx/macro.lua test" + , " xmake macro --import=/xxx/macrodir" } + , {nil, "export", "kv", nil, "Export the given macro to file or directory." , ".e.g" - , " xmake macro --export=/xxx/macro.lua test" } + , " xmake macro --export=/xxx/macro.lua test" + , " xmake macro --export=/xxx/macrodir" } , {} , {nil, "name", "v", ".", "Set the macro name." , ".e.g" |
