summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-05-25 22:27:46 +0800
committerruki <[email protected]>2019-05-25 22:27:46 +0800
commit62e802d3d2bd954c7c101e0eaf792125e2f9e44d (patch)
tree4bad2876a2ffcfc2facb17bf538a90d797349ae9
parent2cae1ff2dc7f1756a8a831cfde5c6610342f978f (diff)
improve confirm
-rw-r--r--xmake/actions/install/main.lua17
-rw-r--r--xmake/actions/require/clean.lua16
-rw-r--r--xmake/actions/require/impl/package.lua15
-rw-r--r--xmake/actions/uninstall/main.lua17
-rw-r--r--xmake/actions/update/main.lua17
-rw-r--r--xmake/core/base/utils.lua6
-rw-r--r--xmake/modules/package/manager/apt/install_package.lua18
-rw-r--r--xmake/modules/package/manager/pacman/install_package.lua18
-rw-r--r--xmake/modules/package/manager/yum/install_package.lua18
9 files changed, 18 insertions, 124 deletions
diff --git a/xmake/actions/install/main.lua b/xmake/actions/install/main.lua
index 0f599bf15..f223b96fa 100644
--- a/xmake/actions/install/main.lua
+++ b/xmake/actions/install/main.lua
@@ -123,23 +123,8 @@ function main()
-- continue to install with administrator permission?
if sudo.has() then
- -- get confirm
- local confirm = option.get("yes")
- if confirm == nil then
-
- -- show tips
- cprint("${bright color.warning}note: ${clear}try continue to install with administrator permission again?")
- cprint("please input: y (y/n)")
-
- -- get answer
- io.flush()
- local answer = io.read()
- if answer == 'y' or answer == '' then
- confirm = true
- end
- end
-
-- confirm to install?
+ local confirm = utils.confirm({default = true, description = "try continue to install with administrator permission again"})
if confirm then
-- install target with administrator permission
diff --git a/xmake/actions/require/clean.lua b/xmake/actions/require/clean.lua
index bcb91b16d..6918fa76d 100644
--- a/xmake/actions/require/clean.lua
+++ b/xmake/actions/require/clean.lua
@@ -53,20 +53,8 @@ function _clear_packagedirs(packagedir)
status = "invalid"
end
if status then
- local confirm = option.get("yes")
- if confirm == nil then
-
- -- show tips
- cprint("${bright color.warning}note: ${clear}remove this ${magenta}%s-%s${clear}/${yellow}%s${clear} (${red}%s${clear}) (pass -y to skip confirm)?", package_name, version, hash, status)
- cprint("please input: y (y/n)")
-
- -- get answer
- io.flush()
- local answer = io.read()
- if answer == 'y' or answer == '' then
- confirm = true
- end
- end
+ local description = string.format("remove this ${magenta}%s-%s${clear}/${yellow}%s${clear} (${red}%s${clear})", package_name, version, hash, status)
+ local confirm = utils.confirm({default = true, description = description})
if confirm then
os.rm(hashdir)
end
diff --git a/xmake/actions/require/impl/package.lua b/xmake/actions/require/impl/package.lua
index 93411a2c4..454b713c4 100644
--- a/xmake/actions/require/impl/package.lua
+++ b/xmake/actions/require/impl/package.lua
@@ -426,8 +426,7 @@ function _get_confirm(packages)
end
-- get confirm
- local confirm = option.get("yes")
- if confirm == nil then
+ local confirm = utils.confirm({default = true, description = function ()
-- get packages for each repositories
local packages_repo = {}
@@ -472,17 +471,7 @@ function _get_confirm(packages)
end
end
end
- cprint("please input: y (y/n)")
-
- -- get answer
- io.flush()
- local answer = io.read()
- if answer == 'y' or answer == '' then
- confirm = true
- end
- end
-
- -- ok?
+ end})
return confirm
end
diff --git a/xmake/actions/uninstall/main.lua b/xmake/actions/uninstall/main.lua
index 45b6150e8..0b6558b42 100644
--- a/xmake/actions/uninstall/main.lua
+++ b/xmake/actions/uninstall/main.lua
@@ -82,23 +82,8 @@ function main()
-- continue to uninstall with administrator permission?
if sudo.has() then
- -- get confirm
- local confirm = option.get("yes")
- if confirm == nil then
-
- -- show tips
- cprint("${bright color.warning}note: ${clear}try continue to uninstall with administrator permission again?")
- cprint("please input: y (y/n)")
-
- -- get answer
- io.flush()
- local answer = io.read()
- if answer == 'y' or answer == '' then
- confirm = true
- end
- end
-
-- confirm to uninstall?
+ local confirm = utils.confirm({default = true, description = "try continue to uninstall with administrator permission again"})
if confirm then
-- uninstall target with administrator permission
diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua
index bd3c7592c..108468a21 100644
--- a/xmake/actions/update/main.lua
+++ b/xmake/actions/update/main.lua
@@ -73,23 +73,8 @@ function _sudo(cmd)
-- continue to install with administrator permission?
if sudo.has() then
- -- get confirm
- local confirm = option.get("yes")
- if confirm == nil then
-
- -- show tips
- cprint("\r${bright color.warning}note: ${clear}try continue to run `%s` with administrator permission again?", cmd)
- cprint("\rplease input: y (y/n)")
-
- -- get answer
- io.flush()
- local answer = io.read()
- if answer == 'y' or answer == '' then
- confirm = true
- end
- end
-
-- confirm to install?
+ local confirm = utils.confirm({default = true, description = "try continue to run `%s` with administrator permission again"})
if confirm then
sudo.vrun(cmd)
return true
diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua
index 03b2f4c36..c19987813 100644
--- a/xmake/core/base/utils.lua
+++ b/xmake/core/base/utils.lua
@@ -253,7 +253,11 @@ function utils.confirm(opt)
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)
+ if type(description) == "function" then
+ description()
+ else
+ utils.cprint("${bright color.warning}note: ${clear}%s (pass -y or --confirm=y/n/d to skip confirm)?", description)
+ end
utils.cprint("please input: %s (y/n)", default and "y" or "n")
-- get answer
diff --git a/xmake/modules/package/manager/apt/install_package.lua b/xmake/modules/package/manager/apt/install_package.lua
index 21d0c648e..9f46cdb98 100644
--- a/xmake/modules/package/manager/apt/install_package.lua
+++ b/xmake/modules/package/manager/apt/install_package.lua
@@ -50,23 +50,9 @@ function main(name, opt)
-- install with administrator permission?
elseif sudo.has() then
- -- get confirm
- local confirm = option.get("yes")
- if confirm == nil then
-
- -- show tips
- cprint("${bright color.warning}note: ${clear}try installing %s with administrator permission?", name)
- cprint("please input: y (y/n)")
-
- -- get answer
- io.flush()
- local answer = io.read()
- if answer == 'y' or answer == '' then
- confirm = true
- end
- end
-
-- install it if be confirmed
+ local description = format("try installing %s with administrator permission", name)
+ local confirm = utils.confirm({default = true, description = description})
if confirm then
sudo.vrunv(apt.program, argv)
end
diff --git a/xmake/modules/package/manager/pacman/install_package.lua b/xmake/modules/package/manager/pacman/install_package.lua
index e16d5293d..f06b698f3 100644
--- a/xmake/modules/package/manager/pacman/install_package.lua
+++ b/xmake/modules/package/manager/pacman/install_package.lua
@@ -53,23 +53,9 @@ function main(name, opt)
-- install with administrator permission?
elseif sudo.has() then
- -- get confirm
- local confirm = option.get("yes")
- if confirm == nil then
-
- -- show tips
- cprint("${bright color.warning}note: ${clear}try installing %s with administrator permission?", name)
- cprint("please input: y (y/n)")
-
- -- get answer
- io.flush()
- local answer = io.read()
- if answer == 'y' or answer == '' then
- confirm = true
- end
- end
-
-- install it if be confirmed
+ local description = format("try installing %s with administrator permission", name)
+ local confirm = utils.confirm({default = true, description = description})
if confirm then
sudo.vrunv(pacman.program, argv)
end
diff --git a/xmake/modules/package/manager/yum/install_package.lua b/xmake/modules/package/manager/yum/install_package.lua
index 19ec93eea..616204eb7 100644
--- a/xmake/modules/package/manager/yum/install_package.lua
+++ b/xmake/modules/package/manager/yum/install_package.lua
@@ -53,23 +53,9 @@ function main(name, opt)
-- install with administrator permission?
elseif sudo.has() then
- -- get confirm
- local confirm = option.get("yes")
- if confirm == nil then
-
- -- show tips
- cprint("${bright color.warning}note: ${clear}try installing %s with administrator permission?", name)
- cprint("please input: y (y/n)")
-
- -- get answer
- io.flush()
- local answer = io.read()
- if answer == 'y' or answer == '' then
- confirm = true
- end
- end
-
-- install it if be confirmed
+ local description = format("try installing %s with administrator permission", name)
+ local confirm = utils.confirm({default = true, description = description})
if confirm then
sudo.vrunv(yum.program, argv)
end