add password to CLI

This commit is contained in:
2023-05-23 09:39:00 +02:00
parent 6000553b95
commit e6d1e0f44a
4 changed files with 84 additions and 41 deletions

20
packages/cli/src/stdin.ts Normal file
View File

@@ -0,0 +1,20 @@
export function getStdin(timeout: number = 10): Promise<string> {
return new Promise<string>((resolve, reject) => {
// Store the data from stdin in a buffer
let buffer = ''
process.stdin.on('data', (d) => (buffer += d.toString()))
// Stop listening for data after the timeout, otherwise hangs indefinitely
const t = setTimeout(() => {
process.stdin.destroy()
resolve('')
}, timeout)
// Listen for end and error events
process.stdin.on('end', () => {
clearTimeout(t)
resolve(buffer.trim())
})
process.stdin.on('error', reject)
})
}