From 7edb59324d1483a37d71a6b71d0c7cb14a9fdc72 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 25 Jul 2018 10:08:25 -0400 Subject: [PATCH] exit immediately option --- src/program.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/program.ts b/src/program.ts index 8a8fe9d452..83664ea282 100644 --- a/src/program.ts +++ b/src/program.ts @@ -493,7 +493,7 @@ export class Program { } } - private processResponse(response: Response) { + private processResponse(response: Response, exitImmediately = false) { if (!response.success) { if (process.env.BW_QUIET !== 'true') { if (process.env.BW_RESPONSE === 'true') { @@ -502,7 +502,11 @@ export class Program { writeLn(chalk.redBright(response.message), true); } } - process.exitCode = 1; + if (exitImmediately) { + process.exit(1); + } else { + process.exitCode = 1; + } return; } @@ -529,7 +533,11 @@ export class Program { writeLn(out, true); } } - process.exitCode = 0; + if (exitImmediately) { + process.exit(0); + } else { + process.exitCode = 0; + } } private getJson(obj: any): string { @@ -567,7 +575,7 @@ export class Program { await this.exitIfNotAuthed(); const hasKey = await this.main.cryptoService.hasKey(); if (!hasKey) { - this.processResponse(Response.error('Vault is locked.')); + this.processResponse(Response.error('Vault is locked.'), true); } } @@ -575,14 +583,14 @@ export class Program { const authed = await this.main.userService.isAuthenticated(); if (authed) { const email = await this.main.userService.getEmail(); - this.processResponse(Response.error('You are already logged in as ' + email + '.')); + this.processResponse(Response.error('You are already logged in as ' + email + '.'), true); } } private async exitIfNotAuthed() { const authed = await this.main.userService.isAuthenticated(); if (!authed) { - this.processResponse(Response.error('You are not logged in.')); + this.processResponse(Response.error('You are not logged in.'), true); } } }