Add option to read config value from stdin

Add --stdin option to the config set commands which reads the value to
set via stdin instead of on the command line.  This allows a more secure
way of entering values and avoids having to deal with multiple layers of
quoting and escapes for special characters.
This commit is contained in:
Hornwitser committed 2021-01-23 13:40:17 +01:00
1 parent 0e21060ea3
commit 2117271992
3 files changed
+53 -6

No files matched your search

+24
View File
@@ -52,8 +52,32 @@ async function timeout(promise, time, timeoutResult) {
}
}
/**
* Read stream to the end and return its content
*
* Reads the stream given asynchronously until the end is reached and
* returns all the data which was read from the stream.
*
* @param {Readable} stream - byte stream to read to the end.
* @returns {Buffer} content of the stream.
*/
async function readStream(stream) {
let chunks = [];
for await (let chunk of stream) {
// Support using ^Z to end input on Windows
if (process.platform === "win32" && stream.isTTY && chunk.toString() === "\x1a\r\n") {
break;
}
chunks.push(chunk);
}
return Buffer.concat(chunks);
}
module.exports = {
basicType,
wait,
timeout,
readStream,
};