mirror of
https://github.com/bitwarden/cli
synced 2025-12-16 16:23:30 +00:00
prompt for unlock if can interact
This commit is contained in:
@@ -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 <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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user