diff --git a/src/commands/export.command.ts b/src/commands/export.command.ts index 950cd43..759b5b0 100644 --- a/src/commands/export.command.ts +++ b/src/commands/export.command.ts @@ -9,6 +9,8 @@ import { MessageResponse } from 'jslib/cli/models/response/messageResponse'; import { CliUtils } from '../utils'; +import { Utils } from 'jslib/misc/utils'; + export class ExportCommand { constructor(private cryptoService: CryptoService, private exportService: ExportService) { } @@ -29,7 +31,17 @@ export class ExportCommand { const storedKeyHash = await this.cryptoService.getKeyHash(); if (storedKeyHash != null && keyHash != null && storedKeyHash === keyHash) { const format = cmd.format !== 'json' ? 'csv' : 'json'; - const csv = await this.exportService.getExport(format); + if (cmd.organizationid != null && !Utils.isGuid(cmd.organizationid)) { + return Response.error('`' + cmd.organizationid + '` is not a GUID.'); + } + let csv: string = null; + try { + csv = cmd.organizationid != null ? + await this.exportService.getOrganizationExport(cmd.organizationid, format) : + await this.exportService.getExport(format); + } catch (e) { + return Response.error(e); + } return await this.saveFile(csv, cmd, format); } else { return Response.error('Invalid master password.'); @@ -38,7 +50,8 @@ export class ExportCommand { async saveFile(csv: string, cmd: program.Command, format: string): Promise { try { - const filePath = await CliUtils.saveFile(csv, cmd.output, this.exportService.getFileName(null, format)); + const filePath = await CliUtils.saveFile(csv, cmd.output, + this.exportService.getFileName(cmd.organizationid != null ? 'org' : null, format)); const res = new MessageResponse('Saved ' + filePath, null); res.raw = filePath; return Response.success(res); diff --git a/src/program.ts b/src/program.ts index f0cc16f..a42ab65 100644 --- a/src/program.ts +++ b/src/program.ts @@ -497,6 +497,7 @@ export class Program extends BaseProgram { .description('Export vault data to a CSV or JSON file.') .option('--output ', 'Output directory or filename.') .option('--format ', 'Export file format.') + .option('--organizationid ', 'Organization id for an organization.') .on('--help', () => { writeLn('\n Notes:'); writeLn(''); @@ -509,6 +510,7 @@ export class Program extends BaseProgram { writeLn(' bw export myPassword321 --format json'); writeLn(' bw export --output ./exp/bw.csv'); writeLn(' bw export myPassword321 --output bw.json --format json'); + writeLn(' bw export myPassword321 --organizationid 7063feab-4b10-472e-b64c-785e2b870b92'); writeLn('', true); }) .action(async (password, cmd) => {