From 80f34d5de5453bb4461179c40532cec5d26b792a Mon Sep 17 00:00:00 2001 From: Hannu Hartikainen Date: Wed, 12 May 2021 05:19:47 +0300 Subject: [PATCH] Add `bw get notes ` command (#255) Rationale: the notes object is a freeform plain-text field that's prominently displayed in Web Vault. It is also useful for the CLI users as discussed before in issues #81 and #196. I have some use cases planned myself. I was rather surprised this wasn't supported already, but the implementation is simple and cannot really break any existing functionality so here it is. --- src/commands/get.command.ts | 18 ++++++++++++++++++ src/vault.program.ts | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/commands/get.command.ts b/src/commands/get.command.ts index 7154c1b1804..2adc54469d6 100644 --- a/src/commands/get.command.ts +++ b/src/commands/get.command.ts @@ -82,6 +82,8 @@ export class GetCommand extends DownloadCommand { return await this.getUri(id); case 'totp': return await this.getTotp(id); + case 'notes': + return await this.getNotes(id); case 'exposed': return await this.getExposed(id); case 'attachment': @@ -239,6 +241,22 @@ export class GetCommand extends DownloadCommand { return Response.success(res); } + private async getNotes(id: string) { + const cipherResponse = await this.getCipher(id, + c => !Utils.isNullOrWhitespace(c.notes)); + if (!cipherResponse.success) { + return cipherResponse; + } + + const cipher = cipherResponse.data as CipherResponse; + if (Utils.isNullOrWhitespace(cipher.notes)) { + return Response.error('No notes available for this item.'); + } + + const res = new StringResponse(cipher.notes); + return Response.success(res); + } + private async getExposed(id: string) { const passwordResponse = await this.getPassword(id); if (!passwordResponse.success) { diff --git a/src/vault.program.ts b/src/vault.program.ts index f9d4ae71bcb..53be3427fda 100644 --- a/src/vault.program.ts +++ b/src/vault.program.ts @@ -87,6 +87,7 @@ export class VaultProgram extends Program { writeLn(' password'); writeLn(' uri'); writeLn(' totp'); + writeLn(' notes'); writeLn(' exposed'); writeLn(' attachment'); writeLn(' folder'); @@ -109,6 +110,7 @@ export class VaultProgram extends Program { writeLn(' bw get item 99ee88d2-6046-4ea7-92c2-acac464b1412'); writeLn(' bw get password https://google.com'); writeLn(' bw get totp google.com'); + writeLn(' bw get notes google.com'); writeLn(' bw get exposed yahoo.com'); writeLn(' bw get attachment b857igwl1dzrs2 --itemid 99ee88d2-6046-4ea7-92c2-acac464b1412 ' + '--output ./photo.jpg');