diff options
| author | ruki <[email protected]> | 2019-05-25 22:03:58 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-05-25 22:03:58 +0800 |
| commit | 2cae1ff2dc7f1756a8a831cfde5c6610342f978f (patch) | |
| tree | 397a3b92fd0405dff31e2cb0ea9cd1d02a5c32fe | |
| parent | e2b3965574e574fafbd76d89ee6f5d18ca1265cd (diff) | |
add confirm option
| -rw-r--r-- | xmake/actions/build/cleaner.lua | 2 | ||||
| -rw-r--r-- | xmake/actions/build/statistics.lua | 2 | ||||
| -rw-r--r-- | xmake/actions/config/main.lua | 29 | ||||
| -rw-r--r-- | xmake/actions/config/menuconf.lua | 3 | ||||
| -rw-r--r-- | xmake/actions/global/menuconf.lua | 3 | ||||
| -rw-r--r-- | xmake/core/base/option.lua | 2 | ||||
| -rw-r--r-- | xmake/core/base/task.lua | 17 | ||||
| -rw-r--r-- | xmake/core/base/utils.lua | 50 | ||||
| -rw-r--r-- | xmake/core/main.lua | 15 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/base/task.lua | 4 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/utils.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/privilege/sudo.lua | 2 |
12 files changed, 83 insertions, 51 deletions
diff --git a/xmake/actions/build/cleaner.lua b/xmake/actions/build/cleaner.lua index 011520674..5b39f5542 100644 --- a/xmake/actions/build/cleaner.lua +++ b/xmake/actions/build/cleaner.lua @@ -40,7 +40,7 @@ function cleanup() -- init argument list local argv = {"lua", path.join(os.scriptdir(), "cleaner.lua")} - for _, name in ipairs({"root", "file", "project", "diagnosis", "verbose", "quiet", "yes"}) do + for _, name in ipairs({"root", "file", "project", "diagnosis", "verbose", "quiet", "yes", "confirm"}) do local value = option.get(name) if type(value) == "string" then table.insert(argv, "--" .. name .. "=" .. value) diff --git a/xmake/actions/build/statistics.lua b/xmake/actions/build/statistics.lua index a3a2a2268..ebce99f13 100644 --- a/xmake/actions/build/statistics.lua +++ b/xmake/actions/build/statistics.lua @@ -70,7 +70,7 @@ function post() -- init argument list local argv = {"lua", path.join(os.scriptdir(), "statistics.lua")} - for _, name in ipairs({"root", "file", "project", "diagnosis", "verbose", "quiet", "yes"}) do + for _, name in ipairs({"root", "file", "project", "diagnosis", "verbose", "quiet", "yes", "confirm"}) do local value = option.get(name) if type(value) == "string" then table.insert(argv, "--" .. name .. "=" .. value) diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index 4cafb68ba..dfd6f8e53 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -20,8 +20,8 @@ -- imports import("core.base.option") -import("core.project.config") import("core.base.global") +import("core.project.config") import("core.project.project") import("core.platform.platform") import("core.project.cache") @@ -41,7 +41,7 @@ function _option_filter(name) , root = true , yes = true , quiet = true - , profile = true + , confirm = true , project = true , verbose = true , diagnosis = true @@ -148,28 +148,13 @@ function main() -- scan project and generate it if xmake.lua not exists if not os.isfile(project.file()) then - -- need some tips? - local autogen = true - if not option.get("quiet") and not option.get("yes") then - - -- show tips - cprint("${bright color.warning}note: ${clear}xmake.lua not found, try generating it (pass -y to skip confirm)?") - cprint("please input: n (y/n)") - - -- get answer - io.flush() - if io.read() ~= 'y' then - autogen = false - end - end - - -- do not generate it - if not autogen then + -- scan and generate it automatically + local autogen = utils.confirm({default = false, description = "xmake.lua not found, try generating it"}) + if autogen then + scangen() + else os.exit() end - - -- scan and generate it automatically - scangen() end -- enter menu config diff --git a/xmake/actions/config/menuconf.lua b/xmake/actions/config/menuconf.lua index e0e5efe53..51ac87f40 100644 --- a/xmake/actions/config/menuconf.lua +++ b/xmake/actions/config/menuconf.lua @@ -77,10 +77,9 @@ function app:_filter_option(name) , root = true , yes = true , quiet = true - , profile = true + , confirm = true , project = true , verbose = true - , backtrace = true , diagnosis = true , require = true , version = true diff --git a/xmake/actions/global/menuconf.lua b/xmake/actions/global/menuconf.lua index 2ff1ab3d2..6b319cef1 100644 --- a/xmake/actions/global/menuconf.lua +++ b/xmake/actions/global/menuconf.lua @@ -75,10 +75,9 @@ function app:_filter_option(name) , root = true , yes = true , quiet = true - , profile = true + , confirm = true , project = true , verbose = true - , backtrace = true , diagnosis = true , version = true , help = true diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua index bb75111fd..9873d8195 100644 --- a/xmake/core/base/option.lua +++ b/xmake/core/base/option.lua @@ -725,8 +725,8 @@ end -- get the boolean value function option.boolean(value) - if type(value) == "string" then + value = value:lower() if value == "true" or value == "yes" or value == "y" then value = true elseif value == "false" or value == "no" or value == "n" then value = false end diff --git a/xmake/core/base/task.lua b/xmake/core/base/task.lua index ea1050251..072219fc9 100644 --- a/xmake/core/base/task.lua +++ b/xmake/core/base/task.lua @@ -128,15 +128,18 @@ function task._translate_menu(menu) -- add common options table.insert(options, 1, {'q', "quiet", "k", nil, "Quiet operation." }) table.insert(options, 2, {'y', "yes", "k", nil, "Input yes by default if need user confirm." }) - table.insert(options, 3, {'v', "verbose", "k", nil, "Print lots of verbose information for users." }) - table.insert(options, 4, {nil, "root", "k", nil, "Allow to run xmake as root." }) - table.insert(options, 5, {'D', "diagnosis", "k", nil, "Print lots of diagnosis information (backtrace, check info ..) only for developers." + table.insert(options, 3, {nil, "confirm", "kv", nil, "Input the given result if need user confirm.", + " - y|yes", + " - n|no", + " - d|def"}) + table.insert(options, 4, {'v', "verbose", "k", nil, "Print lots of verbose information for users." }) + table.insert(options, 5, {nil, "root", "k", nil, "Allow to run xmake as root." }) + table.insert(options, 6, {'D', "diagnosis", "k", nil, "Print lots of diagnosis information (backtrace, check info ..) only for developers." , "And we can append -v to get more whole information." , " e.g. $ xmake -v -D"}) - table.insert(options, 6, {nil, "profile", "k", nil, "Print performance data only for developers." }) - table.insert(options, 7, {nil, "version", "k", nil, "Print the version number and exit." }) - table.insert(options, 8, {'h', "help", "k", nil, "Print this help message and exit." }) - table.insert(options, 9, {nil, "backtrace", "k", nil, "Please uses -D or --diagnosis instead of it. (deprecated)"}) + table.insert(options, 7, {nil, "profile", "k", nil, "Print performance data only for developers." }) + table.insert(options, 8, {nil, "version", "k", nil, "Print the version number and exit." }) + table.insert(options, 9, {'h', "help", "k", nil, "Print this help message and exit." }) table.insert(options, 10, {}) table.insert(options, 11, {'F', "file", "kv", nil, "Read a given xmake.lua file." }) table.insert(options, 12, {'P', "project", "kv", nil, "Change to the given project directory." diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua index bee1a2813..03b2f4c36 100644 --- a/xmake/core/base/utils.lua +++ b/xmake/core/base/utils.lua @@ -216,5 +216,55 @@ function utils.trycall(script, traceback, ...) end, ...) end +-- get confirm result +-- +-- @code +-- if utils.confirm({description = "xmake.lua not found, try generating it", default = true}) then +-- TODO +-- end +-- @endcode +-- +function utils.confirm(opt) + + -- init options + opt = opt or {} + + -- get default + local default = opt.default + if default == nil then + default = false + end + + -- get description + local description = opt.description or "" + + -- get confirm result + local confirm = option.get("yes") or option.get("confirm") + if type(confirm) == "string" then + confirm = confirm:lower() + if confirm == "d" or confirm == "def" then + confirm = default + else + confirm = nil + end + end + + -- get user confirm + if confirm == nil then + + -- show tips + utils.cprint("${bright color.warning}note: ${clear}%s (pass -y or --confirm=y/n/d to skip confirm)?", description) + utils.cprint("please input: %s (y/n)", default and "y" or "n") + + -- get answer + io.flush() + confirm = option.boolean(io.read():trim()) + if type(confirm) ~= "boolean" then + confirm = default + end + end + return confirm +end + -- return module return utils diff --git a/xmake/core/main.lua b/xmake/core/main.lua index 685030a10..5659929d4 100644 --- a/xmake/core/main.lua +++ b/xmake/core/main.lua @@ -28,7 +28,6 @@ local path = require("base/path") local utils = require("base/utils") local option = require("base/option") local global = require("base/global") -local profiler = require("base/profiler") local deprecated = require("base/deprecated") local privilege = require("base/privilege") local task = require("base/task") @@ -36,6 +35,7 @@ local colors = require("base/colors") local theme = require("theme/theme") local project = require("project/project") local history = require("project/history") +--local profiler = require("base/profiler") -- init the option menu local menu = @@ -195,15 +195,8 @@ Or you can add `--root` option or XMAKE_ROOT=y to allow run as root temporarily. end end - -- check deprecated options, TODO it will be removed after v2.3.0 - if option.get("backtrace") then - deprecated.add("-D or --diagnosis", "--backtrace") - end - -- start profiling - if option.get("profile") then - profiler:start() - end + -- profiler:start() -- load global configuration ok, errors = global.load() @@ -249,9 +242,7 @@ Or you can add `--root` option or XMAKE_ROOT=y to allow run as root temporarily. deprecated.dump() -- stop profiling - if option.get("profile") then - profiler:stop() - end + -- profiler:stop() -- close log log:close() diff --git a/xmake/core/sandbox/modules/import/core/base/task.lua b/xmake/core/sandbox/modules/import/core/base/task.lua index f891fe84d..d6cdcef01 100644 --- a/xmake/core/sandbox/modules/import/core/base/task.lua +++ b/xmake/core/sandbox/modules/import/core/base/task.lua @@ -38,8 +38,8 @@ function sandbox_core_base_task.run(taskname, options, ...) options = table.wrap(options) -- inherit some parent options - for _, name in ipairs({"file", "project", "diagnosis", "verbose", "quiet", "yes", "root", "profile"}) do - if not options[name] and option.get(name) then + for _, name in ipairs({"file", "project", "diagnosis", "verbose", "quiet", "yes", "confirm", "root"}) do + if options[name] == nil and option.get(name) ~= nil then options[name] = option.get(name) end end diff --git a/xmake/core/sandbox/modules/utils.lua b/xmake/core/sandbox/modules/utils.lua index b27ce31d3..2d026a600 100644 --- a/xmake/core/sandbox/modules/utils.lua +++ b/xmake/core/sandbox/modules/utils.lua @@ -183,6 +183,11 @@ function sandbox_utils.assert(value, format, ...) return value end +-- get user confirm +function sandbox_utils.confirm(opt) + return utils.confirm(opt) +end + -- return module return sandbox_utils diff --git a/xmake/modules/privilege/sudo.lua b/xmake/modules/privilege/sudo.lua index 39fd8c64c..dd529de91 100644 --- a/xmake/modules/privilege/sudo.lua +++ b/xmake/modules/privilege/sudo.lua @@ -75,7 +75,7 @@ function _lua(runner, luafile, luaargv) -- init argv local argv = {"lua", "--root"} - for _, name in ipairs({"file", "project", "diagnosis", "verbose", "quiet", "yes"}) do + for _, name in ipairs({"file", "project", "diagnosis", "verbose", "quiet", "yes", "confirm"}) do local value = option.get(name) if type(value) == "string" then table.insert(argv, "--" .. name .. "=" .. value) |
