--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, Xmake Open Source Community. -- -- @author ruki -- @file main.lua -- -- imports import("core.base.option") import("core.project.project") import("actions.create.template", {rootdir = os.programdir()}) -- validate template component against path traversal function _validate_template_component(name, value) if #value == 0 or value == "." or value == ".." or value:find("/", 1, true) or value:find("\\", 1, true) or value:find(":", 1, true) or value:find("\0", 1, true) then raise("invalid %s: %s!", name, value) end end -- get template language from template id function _get_language_from_template(templateid) local lang = option.get("language") if lang then _validate_template_component("language", lang) end if not templateid or not lang or template.templatedir(lang, templateid) then return lang end local langs = template.languages_for_template(templateid) if #langs == 1 then return langs[1] elseif #langs > 1 then raise("template(%s): please pass -l/--language, supported languages: %s", templateid, table.concat(langs, ", ")) end return lang end -- get template id from command line options function _get_templateid() local templateid = option.get("template") _validate_template_component("template id", templateid) return templateid end -- get target name from command line options function _get_targetname() return option.get("target") or path.basename(project.directory()) or "demo" end -- list all supported templates for each language -- -- output is in tree format: -- -- --