summaryrefslogtreecommitdiff
path: root/xmake/core/base
diff options
context:
space:
mode:
Diffstat (limited to 'xmake/core/base')
-rw-r--r--xmake/core/base/option.lua2
-rw-r--r--xmake/core/base/task.lua17
-rw-r--r--xmake/core/base/utils.lua50
3 files changed, 61 insertions, 8 deletions
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