1
0
mirror of https://github.com/bitwarden/cli synced 2025-12-17 08:43:21 +00:00

Export to stdout (#152)

* describe file-saving and add helper to write to stdout if appropriate

* allow writing attachments to stdout

* allow writing export to stdout

* add help texts for export and get
This commit is contained in:
Andreas Schneider
2020-08-25 20:24:43 +02:00
committed by GitHub
parent 9f72e0e316
commit f2530c133e
4 changed files with 52 additions and 13 deletions

View File

@@ -35,27 +35,24 @@ export class ExportCommand {
if (cmd.organizationid != null && !Utils.isGuid(cmd.organizationid)) {
return Response.error('`' + cmd.organizationid + '` is not a GUID.');
}
let csv: string = null;
let exportContent: string = null;
try {
csv = cmd.organizationid != null ?
exportContent = 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);
return await this.saveFile(exportContent, cmd, format);
} else {
return Response.error('Invalid master password.');
}
}
async saveFile(csv: string, cmd: program.Command, format: string): Promise<Response> {
async saveFile(exportContent: string, cmd: program.Command, format: string): Promise<Response> {
try {
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);
const fileName = this.exportService.getFileName(cmd.organizationid != null ? 'org' : null, format);
return await CliUtils.saveResultToFile(exportContent, cmd.output, fileName);
} catch (e) {
return Response.error(e.toString());
}