diff options
| author | ruki <[email protected]> | 2015-06-19 18:01:40 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-19 18:01:40 +0800 |
| commit | 2ee74d41c449192a66a2bc5cc1ca64fbc952c626 (patch) | |
| tree | 1ca2f34f24cc47854b6f4a5610036437352e583e /xmake/scripts/action/_create.lua | |
| parent | 1d041891edec9d99a1922fd7f4a4770b60412cfd (diff) | |
add template interfaces for c console
Diffstat (limited to 'xmake/scripts/action/_create.lua')
| -rw-r--r-- | xmake/scripts/action/_create.lua | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/xmake/scripts/action/_create.lua b/xmake/scripts/action/_create.lua index 133e688d3..47d0d2761 100644 --- a/xmake/scripts/action/_create.lua +++ b/xmake/scripts/action/_create.lua @@ -25,9 +25,7 @@ local _create = _create or {} -- load modules local utils = require("base/utils") -local config = require("base/config") local template = require("base/template") -local platform = require("platform/platform") -- need access to the given file? function _create.need(name) @@ -43,6 +41,12 @@ function _create.done() local options = xmake._OPTIONS assert(options) + -- the target name + local targetname = options.target or path.basename(xmake._PROJECT_DIR) or "demo" + + -- trace + utils.printf("create project %s ...", targetname) + -- the language local language = options.language if not language then @@ -50,9 +54,39 @@ function _create.done() return false end - -- the target name - local target_name = options.target or path.basename(xmake._PROJECT_DIR) - print(language, target_name) + -- the template id + local templateid = tonumber(options.template) + if type(templateid) ~= "number" then + utils.error("invalid template id: %s!", options.template) + return false + end + + -- load all templates for the given language + local templates = template.loadall(language) + + -- load the template module + local module = nil + if templates then module = templates[templateid] end + if not module then + utils.error("invalid template id: %s!", options.template) + return false + end + + -- enter the template directory + if not module._DIRECTORY or not os.cd(module._DIRECTORY) then + -- error + utils.error("not found template id: %s!", options.template) + return false + end + + -- done the template and create this project + if not module.done(targetname, xmake._PROJECT_DIR) then + utils.error("create project %s failed!", targetname) + return false + end + + -- trace + utils.printf("create project %s ok!", targetname) -- ok return true |
