Software / code / prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
| 4481:408c2f688e4e | 4485:abfd27b59fa8 |
|---|---|
| 14 local usermanager = require "core.usermanager"; | 14 local usermanager = require "core.usermanager"; |
| 15 local signal = require "util.signal"; | 15 local signal = require "util.signal"; |
| 16 local set = require "util.set"; | 16 local set = require "util.set"; |
| 17 local lfs = require "lfs"; | 17 local lfs = require "lfs"; |
| 18 local pcall = pcall; | 18 local pcall = pcall; |
| 19 local type = type; | |
| 19 | 20 |
| 20 local nodeprep, nameprep = stringprep.nodeprep, stringprep.nameprep; | 21 local nodeprep, nameprep = stringprep.nodeprep, stringprep.nameprep; |
| 21 | 22 |
| 22 local io, os = io, os; | 23 local io, os = io, os; |
| 23 local print = print; | 24 local print = print; |
| 61 if ok then | 62 if ok then |
| 62 return char; | 63 return char; |
| 63 end | 64 end |
| 64 end | 65 end |
| 65 | 66 |
| 67 function getline() | |
| 68 local ok, line = pcall(io.read, "*l"); | |
| 69 if ok then | |
| 70 return line; | |
| 71 end | |
| 72 end | |
| 73 | |
| 66 function getpass() | 74 function getpass() |
| 67 local stty_ret = os.execute("stty -echo 2>/dev/null"); | 75 local stty_ret = os.execute("stty -echo 2>/dev/null"); |
| 68 if stty_ret ~= 0 then | 76 if stty_ret ~= 0 then |
| 69 io.write("\027[08m"); -- ANSI 'hidden' text attribute | 77 io.write("\027[08m"); -- ANSI 'hidden' text attribute |
| 70 end | 78 end |
| 110 end | 118 end |
| 111 end | 119 end |
| 112 return password; | 120 return password; |
| 113 end | 121 end |
| 114 | 122 |
| 123 function show_prompt(prompt) | |
| 124 io.write(prompt, " "); | |
| 125 local line = getline(); | |
| 126 line = line and line:gsub("\n$",""); | |
| 127 return (line and #line > 0) and line or nil; | |
| 128 end | |
| 129 | |
| 115 -- Server control | 130 -- Server control |
| 116 function adduser(params) | 131 function adduser(params) |
| 117 local user, host, password = nodeprep(params.user), nameprep(params.host), params.password; | 132 local user, host, password = nodeprep(params.user), nameprep(params.host), params.password; |
| 118 if not user then | 133 if not user then |
| 119 return false, "invalid-username"; | 134 return false, "invalid-username"; |