mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-09 20:57:44 +00:00
fix: hide user input when logging in
This commit is contained in:
@@ -35,7 +35,8 @@ export async function handlePush (argv: {
|
||||
const isAuthorized = await client.isAuthorizedWithRedocly();
|
||||
if (!isAuthorized) {
|
||||
const clientToken = await promptUser(
|
||||
green(`\n 🔑 Copy your API key from ${blue('https://app.redoc.ly/profile')} and paste it below`)
|
||||
green(`\n 🔑 Copy your API key from ${blue('https://app.redoc.ly/profile')} and paste it below`),
|
||||
true
|
||||
);
|
||||
await client.login(clientToken);
|
||||
}
|
||||
|
||||
@@ -185,6 +185,7 @@ yargs
|
||||
`https://app.${process.env.REDOCLY_DOMAIN || 'redoc.ly'}/profile`,
|
||||
)} and paste it below`,
|
||||
),
|
||||
true
|
||||
);
|
||||
const client = new RedoclyClient();
|
||||
client.login(clientToken);
|
||||
|
||||
@@ -6,6 +6,7 @@ import * as yaml from 'js-yaml';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as readline from 'readline';
|
||||
import { Writable } from 'stream';
|
||||
import {
|
||||
BundleOutputFormat,
|
||||
Config,
|
||||
@@ -119,17 +120,35 @@ export function saveBundle(filename: string, output: string) {
|
||||
fs.writeFileSync(filename, output);
|
||||
}
|
||||
|
||||
export async function promptUser(query: string): Promise<string> {
|
||||
export async function promptUser(query: string, hideUserInput = false): Promise<string> {
|
||||
return new Promise((resolve) => {
|
||||
let output: Writable = process.stdout;
|
||||
let isOutputMuted = false;
|
||||
|
||||
if (hideUserInput) {
|
||||
output = new Writable({
|
||||
write: (chunk, encoding, callback) => {
|
||||
if (!isOutputMuted) {
|
||||
process.stdout.write(chunk, encoding);
|
||||
}
|
||||
callback();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
output,
|
||||
terminal: true,
|
||||
historySize: hideUserInput ? 0 : 30,
|
||||
});
|
||||
|
||||
rl.question(`${query}:\n\n `, (answer) => {
|
||||
rl.close();
|
||||
resolve(answer);
|
||||
});
|
||||
|
||||
isOutputMuted = hideUserInput;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user