Add `bw get notes <id>` 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.
This commit is contained in:
Hannu Hartikainen 2021-05-12 05:19:47 +03:00 committed by GitHub
parent b4fc4ca3a5
commit 80f34d5de5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -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) {

View File

@ -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');