Diff

util/prosodyctl.lua @ 4485:abfd27b59fa8

util.prosodyctl: Add getline() and show_prompt()
author Kim Alvefur <zash@zash.se>
date Fri, 20 Jan 2012 21:58:04 +0100
parent 4335:3a2a01432b5c
child 4500:bfa387f268e2
line wrap: on
line diff
--- a/util/prosodyctl.lua	Thu Jan 19 16:47:12 2012 +0100
+++ b/util/prosodyctl.lua	Fri Jan 20 21:58:04 2012 +0100
@@ -16,6 +16,7 @@
 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 @@
 	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 @@
 	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;