diff --git a/jslib b/jslib index 8ab36db5c6..57e49207e9 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 8ab36db5c6d07724326853207690338a27589f43 +Subproject commit 57e49207e9ad57c71576fc487a38513a4d0fe120 diff --git a/src/commands/export.command.ts b/src/commands/export.command.ts index 759b5b0ea3..18c522bffb 100644 --- a/src/commands/export.command.ts +++ b/src/commands/export.command.ts @@ -15,7 +15,8 @@ export class ExportCommand { constructor(private cryptoService: CryptoService, private exportService: ExportService) { } async run(password: string, cmd: program.Command): Promise { - if (password == null || password === '') { + const canInteract = process.stdout.isTTY && process.env.BW_NOINTERACTION !== 'true'; + if ((password == null || password === '') && canInteract) { const answer: inquirer.Answers = await inquirer.createPromptModule({ output: process.stderr })({ type: 'password', name: 'password', diff --git a/src/commands/unlock.command.ts b/src/commands/unlock.command.ts index f38a333422..8f3e7614b0 100644 --- a/src/commands/unlock.command.ts +++ b/src/commands/unlock.command.ts @@ -15,7 +15,8 @@ export class UnlockCommand { private cryptoFunctionService: CryptoFunctionService) { } async run(password: string, cmd: program.Command) { - if (password == null || password === '') { + const canInteract = process.stdout.isTTY && process.env.BW_NOINTERACTION !== 'true'; + if ((password == null || password === '') && canInteract) { const answer: inquirer.Answers = await inquirer.createPromptModule({ output: process.stderr })({ type: 'password', name: 'password', diff --git a/src/program.ts b/src/program.ts index b4c85f5f99..249ac65b73 100644 --- a/src/program.ts +++ b/src/program.ts @@ -45,6 +45,7 @@ export class Program extends BaseProgram { .option('--raw', 'Return raw output instead of a descriptive message.') .option('--response', 'Return a JSON formatted version of response output.') .option('--quiet', 'Don\'t return anything to stdout.') + .option('--nointeraction', 'Do not prompt for interactive user input.') .option('--session ', 'Pass session key instead of reading from env.') .version(this.main.platformUtilsService.getApplicationVersion(), '-v, --version'); @@ -64,6 +65,10 @@ export class Program extends BaseProgram { process.env.BW_RESPONSE = 'true'; }); + program.on('option:nointeraction', () => { + process.env.BW_NOINTERACTION = 'true'; + }); + program.on('option:session', (key) => { process.env.BW_SESSION = key; }); @@ -640,7 +645,17 @@ export class Program extends BaseProgram { await this.exitIfNotAuthed(); const hasKey = await this.main.cryptoService.hasKey(); if (!hasKey) { - this.processResponse(Response.error('Vault is locked.'), true); + const canInteract = process.stdout.isTTY && process.env.BW_NOINTERACTION !== 'true'; + if (canInteract) { + const command = new UnlockCommand(this.main.cryptoService, this.main.userService, + this.main.cryptoFunctionService); + const response = await command.run(null, null); + if (!response.success) { + this.processResponse(response, true); + } + } else { + this.processResponse(Response.error('Vault is locked.'), true); + } } } }