summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-09-20 22:43:55 +0800
committerruki <[email protected]>2017-09-20 10:23:34 +0800
commit29d8859222252ffa54536c0d324290a0c9f2eb41 (patch)
treedaf38b4f51fcdfafc388edbcb96107ce30a5195a
parent218e2711e1afacd334ce50b37b0fa2d2db573e8e (diff)
add --yes to confirm the user input
-rw-r--r--CHANGELOG.md2
-rw-r--r--xmake/actions/build/statistics.lua2
-rw-r--r--xmake/actions/config/main.lua2
-rw-r--r--xmake/actions/install/main.lua24
-rw-r--r--xmake/actions/uninstall/main.lua24
-rw-r--r--xmake/core/base/task.lua21
-rw-r--r--xmake/core/sandbox/modules/import/core/base/task.lua2
-rw-r--r--xmake/modules/devel/package/apt.lua1
-rw-r--r--xmake/modules/devel/package/manager.lua2
-rw-r--r--xmake/modules/devel/package/pacman.lua1
-rw-r--r--xmake/modules/devel/package/yum.lua1
-rw-r--r--xmake/modules/privilege/sudo.lua2
12 files changed, 55 insertions, 29 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 31478c741..da2c0c6a9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@
### New features
* Add `add_imports` to bulk import modules for the target, option and package script
+* Add `xmake -y/--yes` to confirm the user input by default
### Changes
@@ -364,6 +365,7 @@
### 新特性
* 添加`add_imports`去为target,option和package的自定义脚本批量导入模块,简化自定义脚本
+* 添加`xmake -y/--yes`去确认用户输入
### 改进
diff --git a/xmake/actions/build/statistics.lua b/xmake/actions/build/statistics.lua
index 0bffbbe02..e70726b11 100644
--- a/xmake/actions/build/statistics.lua
+++ b/xmake/actions/build/statistics.lua
@@ -71,7 +71,7 @@ function post()
-- init argument list
local argv = {"lua", path.join(os.scriptdir(), "statistics.lua")}
- for _, name in ipairs({"root", "file", "project", "backtrace", "verbose", "quiet"}) do
+ for _, name in ipairs({"root", "file", "project", "backtrace", "verbose", "quiet", "yes"}) 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 47c3c14ef..6b3e3222d 100644
--- a/xmake/actions/config/main.lua
+++ b/xmake/actions/config/main.lua
@@ -149,7 +149,7 @@ function main()
-- need some tips?
local autogen = true
- if not option.get("quiet") then
+ if not option.get("quiet") and not option.get("yes") then
-- show tips
cprint("${bright yellow}note: ${default yellow}xmake.lua not found, try generating it?")
diff --git a/xmake/actions/install/main.lua b/xmake/actions/install/main.lua
index 15f743c97..8d6ef4db0 100644
--- a/xmake/actions/install/main.lua
+++ b/xmake/actions/install/main.lua
@@ -112,14 +112,24 @@ function main()
-- continue to install with administrator permission?
if sudo.has() then
- -- show tips
- cprint("${bright yellow}note: ${default yellow}try continue to install with administrator permission again?")
- cprint("please input: y (y/n)")
+ -- get confirm
+ local confirm = option.get("yes")
+ if confirm == nil then
- -- get answer
- io.flush()
- local answer = io.read()
- if answer == 'y' or answer == '' then
+ -- show tips
+ cprint("${bright yellow}note: ${default yellow}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?
+ if confirm then
-- install target with administrator permission
sudo.runl(path.join(os.scriptdir(), "install_admin.lua"), {targetname or ifelse(option.get("all"), "__all", "__def"), installdir})
diff --git a/xmake/actions/uninstall/main.lua b/xmake/actions/uninstall/main.lua
index d93c5ac06..ed7e5f497 100644
--- a/xmake/actions/uninstall/main.lua
+++ b/xmake/actions/uninstall/main.lua
@@ -112,14 +112,24 @@ function main()
-- continue to uninstall with administrator permission?
if sudo.has() then
- -- show tips
- cprint("${bright yellow}note: ${default yellow}try continue to uninstall with administrator permission again?")
- cprint("please input: y (y/n)")
+ -- get confirm
+ local confirm = option.get("yes")
+ if confirm == nil then
- -- get answer
- io.flush()
- local answer = io.read()
- if answer == 'y' or answer == '' then
+ -- show tips
+ cprint("${bright yellow}note: ${default yellow}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?
+ if confirm then
-- uninstall target with administrator permission
sudo.runl(path.join(os.scriptdir(), "uninstall_admin.lua"), {targetname or "__all", installdir})
diff --git a/xmake/core/base/task.lua b/xmake/core/base/task.lua
index 757b1fcf3..ad4b787ba 100644
--- a/xmake/core/base/task.lua
+++ b/xmake/core/base/task.lua
@@ -132,20 +132,21 @@ function task._translate_menu(menu)
-- add common options
table.insert(options, 1, {'q', "quiet", "k", nil, "Quiet operation." })
- table.insert(options, 2, {'v', "verbose", "k", nil, "Print lots of verbose information." })
- table.insert(options, 3, {nil, "root", "k", nil, "Allow to run xmake as root." })
- table.insert(options, 4, {nil, "backtrace", "k", nil, "Print backtrace information for debugging." })
- table.insert(options, 5, {nil, "profile", "k", nil, "Print performance data for debugging." })
- table.insert(options, 6, {nil, "version", "k", nil, "Print the version number and exit." })
- table.insert(options, 7, {'h', "help", "k", nil, "Print this help message and exit." })
- table.insert(options, 8, {})
- table.insert(options, 9, {'F', "file", "kv", nil, "Read a given xmake.lua file." })
- table.insert(options, 10, {'P', "project", "kv", nil, "Change to the given project directory."
+ 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." })
+ table.insert(options, 4, {nil, "root", "k", nil, "Allow to run xmake as root." })
+ table.insert(options, 5, {nil, "backtrace", "k", nil, "Print backtrace information for debugging." })
+ table.insert(options, 6, {nil, "profile", "k", nil, "Print performance data for debugging." })
+ 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, {})
+ table.insert(options, 10, {'F', "file", "kv", nil, "Read a given xmake.lua file." })
+ table.insert(options, 11, {'P', "project", "kv", nil, "Change to the given project directory."
, "Search priority:"
, " 1. The Given Command Argument"
, " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR"
, " 3. The Current Directory" })
- table.insert(options, 11, {})
+ table.insert(options, 12, {})
end
diff --git a/xmake/core/sandbox/modules/import/core/base/task.lua b/xmake/core/sandbox/modules/import/core/base/task.lua
index b63c965ea..88a4f6080 100644
--- a/xmake/core/sandbox/modules/import/core/base/task.lua
+++ b/xmake/core/sandbox/modules/import/core/base/task.lua
@@ -41,7 +41,7 @@ function sandbox_core_base_task.run(taskname, options, ...)
options = table.wrap(options)
-- inherit some parent options
- for _, name in ipairs({"file", "project", "backtrace", "verbose", "quiet", "root", "profile"}) do
+ for _, name in ipairs({"file", "project", "backtrace", "verbose", "quiet", "yes", "root", "profile"}) do
if not options[name] and option.get(name) then
options[name] = option.get(name)
end
diff --git a/xmake/modules/devel/package/apt.lua b/xmake/modules/devel/package/apt.lua
index b44801bd2..c41377853 100644
--- a/xmake/modules/devel/package/apt.lua
+++ b/xmake/modules/devel/package/apt.lua
@@ -50,6 +50,7 @@ function install(name, opt)
table.insert(argv, "--verbose")
end
+ -- TOOD sudo
-- install package
os.vrunv(apt.program, argv)
diff --git a/xmake/modules/devel/package/manager.lua b/xmake/modules/devel/package/manager.lua
index f927c263d..9324948dd 100644
--- a/xmake/modules/devel/package/manager.lua
+++ b/xmake/modules/devel/package/manager.lua
@@ -31,7 +31,7 @@ import("pacman")
-- install package using third-party package manager
--
-- @param name the package name
--- @param opt the options, .e.g {verbose = true, brew = "the package name in brew", pacman = "xxx", apt = "xxx"}
+-- @param opt the options, .e.g {verbose = true, brew = "the package name in brew", pacman = "xxx", apt = "xxx", yum = "xxx"}
--
--
function install(name, opt)
diff --git a/xmake/modules/devel/package/pacman.lua b/xmake/modules/devel/package/pacman.lua
index fdf8827bb..dd9bb0257 100644
--- a/xmake/modules/devel/package/pacman.lua
+++ b/xmake/modules/devel/package/pacman.lua
@@ -50,6 +50,7 @@ function install(name, opt)
table.insert(argv, "--verbose")
end
+ -- TODO sudo
-- install package
os.vrunv(pacman.program, argv)
diff --git a/xmake/modules/devel/package/yum.lua b/xmake/modules/devel/package/yum.lua
index f4f951fde..62ace253d 100644
--- a/xmake/modules/devel/package/yum.lua
+++ b/xmake/modules/devel/package/yum.lua
@@ -50,6 +50,7 @@ function install(name, opt)
table.insert(argv, "--verbose")
end
+ -- TODO sudo
-- install package
os.vrunv(yum.program, argv)
diff --git a/xmake/modules/privilege/sudo.lua b/xmake/modules/privilege/sudo.lua
index 940dec365..30a7377d8 100644
--- a/xmake/modules/privilege/sudo.lua
+++ b/xmake/modules/privilege/sudo.lua
@@ -79,7 +79,7 @@ function _lua(runner, luafile, luaargv)
-- init argv
local argv = {"lua", "--root"}
- for _, name in ipairs({"file", "project", "backtrace", "verbose", "quiet"}) do
+ for _, name in ipairs({"file", "project", "backtrace", "verbose", "quiet", "yes"}) do
local value = option.get(name)
if type(value) == "string" then
table.insert(argv, "--" .. name .. "=" .. value)