1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00

switch from readline sync to inquirer

This commit is contained in:
Kyle Spearrin
2018-05-23 11:16:23 -04:00
parent 8207e703ac
commit 200effe772
5 changed files with 336 additions and 37 deletions

View File

@@ -1,7 +1,7 @@
import * as program from 'commander';
import * as fs from 'fs';
import * as inquirer from 'inquirer';
import * as path from 'path';
import * as readline from 'readline-sync';
import { CryptoService } from 'jslib/abstractions/crypto.service';
import { ExportService } from 'jslib/abstractions/export.service';
@@ -19,10 +19,13 @@ export class ExportCommand {
async run(password: string, cmd: program.Command): Promise<Response> {
if (password == null || password === '') {
password = readline.question('Master password: ', {
hideEchoBack: true,
const answer = await inquirer.prompt<any>({
type: 'password',
name: 'password',
message: 'Master password:',
mask: '*',
});
password = answer.password;
}
if (password == null || password === '') {
return Response.badRequest('Master password is required.');

View File

@@ -1,5 +1,5 @@
import * as program from 'commander';
import * as readline from 'readline-sync';
import * as inquirer from 'inquirer';
import { TwoFactorProviderType } from 'jslib/enums/twoFactorProviderType';
@@ -22,7 +22,12 @@ export class LoginCommand {
async run(email: string, password: string, cmd: program.Command) {
if (email == null || email === '') {
email = readline.question('Email address: ');
const answer = await inquirer.prompt<any>({
type: 'input',
name: 'email',
message: 'Email address:',
});
email = answer.email;
}
if (email == null || email.trim() === '') {
return Response.badRequest('Email address is required.');
@@ -32,10 +37,13 @@ export class LoginCommand {
}
if (password == null || password === '') {
password = readline.question('Master password: ', {
hideEchoBack: true,
const answer = await inquirer.prompt<any>({
type: 'password',
name: 'password',
message: 'Master password:',
mask: '*',
});
password = answer.password;
}
if (password == null || password === '') {
return Response.badRequest('Master password is required.');
@@ -79,8 +87,16 @@ export class LoginCommand {
selectedProvider = twoFactorProviders[0];
} else {
const options = twoFactorProviders.map((p) => p.name);
const i = readline.keyInSelect(options, 'Two-step login method: ', { cancel: 'Cancel' });
if (i < 0) {
options.push(new inquirer.Separator());
options.push('Cancel');
const answer = await inquirer.prompt<any>({
type: 'list',
name: 'method',
message: 'Two-step login method:',
choices: options,
});
const i = options.indexOf(answer.method);
if (i === (options.length - 1)) {
return Response.error('Login failed.');
}
selectedProvider = twoFactorProviders[i];
@@ -95,7 +111,12 @@ export class LoginCommand {
}
if (twoFactorToken == null) {
twoFactorToken = readline.question('Two-step login code for ' + selectedProvider.name + ': ');
const answer = await inquirer.prompt<any>({
type: 'input',
name: 'token',
message: 'Two-step login code:',
});
twoFactorToken = answer.token;
if (twoFactorToken == null || twoFactorToken === '') {
return Response.badRequest('Code is required.');
}

View File

@@ -1,5 +1,5 @@
import * as program from 'commander';
import * as readline from 'readline-sync';
import * as inquirer from 'inquirer';
import { CryptoService } from 'jslib/abstractions/crypto.service';
import { CryptoFunctionService } from 'jslib/abstractions/cryptoFunction.service';
@@ -16,10 +16,13 @@ export class UnlockCommand {
async run(password: string, cmd: program.Command) {
if (password == null || password === '') {
password = readline.question('Master password: ', {
hideEchoBack: true,
const answer = await inquirer.prompt<any>({
type: 'password',
name: 'password',
message: 'Master password:',
mask: '*',
});
password = answer.password;
}
if (password == null || password === '') {
return Response.badRequest('Master password is required.');