-
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f8f94e
commit 00137ff
Showing
3 changed files
with
79 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const {createInterface} = require('readline'); | ||
|
||
/** | ||
* @returns {Promise<{accountName: string, password: string}>} | ||
*/ | ||
module.exports = async function collectCredentials() { | ||
let accountName = await promptAsync('Account Name: '); | ||
let password = await promptAsync('Password: ', true); | ||
return {accountName, password}; | ||
} | ||
|
||
/** | ||
* | ||
* @param {string} question | ||
* @param {boolean} [sensitiveInput=false] | ||
* @return Promise<string> | ||
*/ | ||
function promptAsync(question, sensitiveInput) { | ||
return new Promise((resolve) => { | ||
let rl = createInterface({ | ||
input: process.stdin, | ||
output: sensitiveInput ? null : process.stdout, | ||
terminal: true | ||
}); | ||
|
||
if (sensitiveInput) { | ||
// We have to write the question manually if we didn't give readline an output stream | ||
process.stdout.write(`${question.trim()} [masked] `); | ||
} | ||
|
||
rl.question(question, (result) => { | ||
if (sensitiveInput) { | ||
// We have to manually print a newline | ||
process.stdout.write('\n'); | ||
} | ||
|
||
rl.close(); | ||
resolve(result); | ||
}); | ||
}); | ||
} |