aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2012-01-20 21:58:04 +0100
committerKim Alvefur <zash@zash.se>2012-01-20 21:58:04 +0100
commit72fcc7b12d296135eb828ed3f8b151171d9d5f1e (patch)
tree94ea31c96d23ed3df11f8e62c41e3f467e3bab84
parent3d9ca327ce10f2bb4d5af85c1695fe70dcf6dbe3 (diff)
downloadprosody-72fcc7b12d296135eb828ed3f8b151171d9d5f1e.tar.gz
prosody-72fcc7b12d296135eb828ed3f8b151171d9d5f1e.zip
util.prosodyctl: Add getline() and show_prompt()
-rw-r--r--util/prosodyctl.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua
index d0045abc..8c58f2cd 100644
--- a/util/prosodyctl.lua
+++ b/util/prosodyctl.lua
@@ -16,6 +16,7 @@ local signal = require "util.signal";
local set = require "util.set";
local lfs = require "lfs";
local pcall = pcall;
+local type = type;
local nodeprep, nameprep = stringprep.nodeprep, stringprep.nameprep;
@@ -63,6 +64,13 @@ function getchar(n)
end
end
+function getline()
+ local ok, line = pcall(io.read, "*l");
+ if ok then
+ return line;
+ end
+end
+
function getpass()
local stty_ret = os.execute("stty -echo 2>/dev/null");
if stty_ret ~= 0 then
@@ -112,6 +120,13 @@ function read_password()
return password;
end
+function show_prompt(prompt)
+ io.write(prompt, " ");
+ local line = getline();
+ line = line and line:gsub("\n$","");
+ return (line and #line > 0) and line or nil;
+end
+
-- Server control
function adduser(params)
local user, host, password = nodeprep(params.user), nameprep(params.host), params.password;