Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions bolt/src/fetch.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const http = require('node:http');
const https = require('node:https');
const fs = require('node:fs');
const path = require('node:path');
const readline = require('node:readline/promises');
const readline = require('node:readline');
const { Transform } = require('node:stream');
const { pipeline } = require('node:stream/promises');
const { spawnSync } = require('node:child_process');
Expand Down Expand Up @@ -131,16 +131,20 @@ function postJSON(url, body) {
});
}

function question(rl, prompt) {
return new Promise((resolve) => rl.question(prompt, resolve));
}

async function promptCredentials(username) {
if (!process.stdin.isTTY) {
throw new Error('Cannot prompt for credentials: stdin is not a terminal');
}
const rl = readline.createInterface({ input: process.stdin, output: process.stderr, terminal: false });
try {
username = username || await rl.question('Username: ');
username = username || await question(rl, 'Username: ');
const echoOff = spawnSync('stty', ['-echo'], { stdio: 'inherit' }).status === 0;
try {
const password = await rl.question('Password: ');
const password = await question(rl, 'Password: ');
if (echoOff) process.stderr.write('\n');
return { username, password };
} finally {
Expand Down
Loading