Software /
code /
prosody
Changeset
4485:abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 20 Jan 2012 21:58:04 +0100 |
parents | 4481:408c2f688e4e |
children | 4486:f04db5e7e90d |
files | util/prosodyctl.lua |
diffstat | 1 files changed, 15 insertions(+), 0 deletions(-) [+] |
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;