summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-19 15:24:59 +0800
committerruki <[email protected]>2015-06-19 15:24:59 +0800
commitc93c5254d82a621a116dbbcd0130b08f5e33ce2b (patch)
treef7df80491e1f72ba37452b001ded9de371e2eba1
parent379675ca870210abdde87db7dfd989855d337cd3 (diff)
list languages and templates
-rw-r--r--xmake/scripts/action/_create.lua55
-rw-r--r--xmake/scripts/base/template.lua74
-rw-r--r--xmake/templates/c++/console/_template.lua (renamed from xmake/templates/c++/console/template.lua)0
-rw-r--r--xmake/templates/c/console/_template.lua (renamed from xmake/templates/c/console/template.lua)13
4 files changed, 122 insertions, 20 deletions
diff --git a/xmake/scripts/action/_create.lua b/xmake/scripts/action/_create.lua
index c4e64a222..5b072b135 100644
--- a/xmake/scripts/action/_create.lua
+++ b/xmake/scripts/action/_create.lua
@@ -26,14 +26,27 @@ 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")
-- done the given config
function _create.done()
- -- TODO
- print("not implement!")
-
+ -- the options
+ local options = xmake._OPTIONS
+ assert(options)
+
+ -- the language
+ local language = options.language
+ if not language then
+ utils.error("no language!")
+ return false
+ end
+
+ -- the target name
+ local target_name = options.target or path.basename(xmake._PROJECT_DIR)
+ print(language, target_name)
+
-- ok
return true
end
@@ -62,17 +75,29 @@ function _create.menu()
, " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR"
, " 3. The Current Directory" }
, {'l', "language", "kv", "c", "The project language"
- , " - c"
- , " - c++"
- , " - objc"
- , " - objc++" }
- , {'t', "type", "kv", "1", "The project type"
- , " 1. The Console Program"
- , " 2. The Console Program with tbox"
- , " 3. The Static Library"
- , " 4. The Static Library with tbox"
- , " 5. The Shared Library"
- , " 6. The Shared Library with tbox" }
+ , function ()
+ local descriptions = {}
+ local languages = template.languages()
+ for _, language in ipairs(languages) do
+ table.insert(descriptions, " - " .. language)
+ end
+ return descriptions
+ end }
+ , {'t', "template", "kv", "1", "Select the project template id of the given language."
+ , function ()
+ local descriptions = {}
+ local languages = template.languages()
+ for _, language in ipairs(languages) do
+ table.insert(descriptions, string.format(" - language: %s", language))
+ local templates = template.loadall(language)
+ if templates then
+ for i, template in ipairs(templates) do
+ table.insert(descriptions, string.format(" %d. %s", i, utils.ifelse(template.description, template.description, "The Unknown Project")))
+ end
+ end
+ end
+ return descriptions
+ end }
, {}
, {'v', "verbose", "k", nil, "Print lots of verbose information." }
@@ -80,7 +105,7 @@ function _create.menu()
, {'h', "help", "k", nil, "Print this help message and exit." }
, {}
- , {nil, "target", "v", nil, "Create the given target"
+ , {nil, "target", "v", nil, "Create the given target."
, "Uses the project name as target if not exists." }
}
}
diff --git a/xmake/scripts/base/template.lua b/xmake/scripts/base/template.lua
new file mode 100644
index 000000000..520321489
--- /dev/null
+++ b/xmake/scripts/base/template.lua
@@ -0,0 +1,74 @@
+--!The Automatic Cross-platform Build Tool
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2009 - 2015, ruki All rights reserved.
+--
+-- @author ruki
+-- @file template.lua
+--
+
+-- define module: template
+local template = template or {}
+
+-- load modules
+local os = require("base/os")
+local path = require("base/path")
+local utils = require("base/utils")
+
+-- get the language list
+function template.languages()
+
+ -- make list
+ local list = {}
+
+ -- get the language list
+ local languages = os.match(xmake._TEMPLATES_DIR .. "/*", true)
+ if languages then
+ for _, v in ipairs(languages) do
+ table.insert(list, path.basename(v))
+ end
+ end
+
+ -- ok?
+ return list
+end
+
+-- load all templates from the given language
+function template.loadall(language)
+
+ -- check
+ assert(language)
+
+ -- load all templates
+ local modules = {}
+ local templates = os.match(string.format("%s/%s/**/_template.lua", xmake._TEMPLATES_DIR, language))
+ if templates then
+ for _, t in ipairs(templates) do
+ local script = assert(loadfile(t))
+ if script then
+ local module = script()
+ if module then table.insert(modules, module) end
+ end
+ end
+ end
+
+ -- ok?
+ return modules
+end
+
+
+-- return module: template
+return template
diff --git a/xmake/templates/c++/console/template.lua b/xmake/templates/c++/console/_template.lua
index 0cf6efff2..0cf6efff2 100644
--- a/xmake/templates/c++/console/template.lua
+++ b/xmake/templates/c++/console/_template.lua
diff --git a/xmake/templates/c/console/template.lua b/xmake/templates/c/console/_template.lua
index 0cf6efff2..a61ef2345 100644
--- a/xmake/templates/c/console/template.lua
+++ b/xmake/templates/c/console/_template.lua
@@ -17,11 +17,14 @@
-- Copyright (C) 2009 - 2015, ruki All rights reserved.
--
-- @author ruki
--- @file template.lua
+-- @file _template.lua
--
--- define module: template
-local template = template or {}
+-- define module: _template
+local _template = _template or {}
--- return module: template
-return template
+-- init the template description
+_template.description = "The Console Program"
+
+-- return module: _template
+return _template