# HG changeset patch # User Kim Alvefur # Date 1327093084 -3600 # Node ID abfd27b59fa87c473f2d8410307e84855bdb3758 # Parent 408c2f688e4e02646456e1567b19809452ee2434 util.prosodyctl: Add getline() and show_prompt() diff -r 408c2f688e4e -r abfd27b59fa8 util/prosodyctl.lua --- 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;