1
0
mirror of https://github.com/bitwarden/cli synced 2025-12-17 16:53:13 +00:00

export file format option

This commit is contained in:
Kyle Spearrin
2018-12-17 10:36:40 -05:00
parent 33deb4cda6
commit 920ce30dd0
3 changed files with 15 additions and 8 deletions

View File

@@ -28,16 +28,17 @@ export class ExportCommand {
const keyHash = await this.cryptoService.hashPassword(password, null);
const storedKeyHash = await this.cryptoService.getKeyHash();
if (storedKeyHash != null && keyHash != null && storedKeyHash === keyHash) {
const csv = await this.exportService.getExport('csv');
return await this.saveFile(csv, cmd);
const format = cmd.format !== 'json' ? 'csv' : 'json';
const csv = await this.exportService.getExport(format);
return await this.saveFile(csv, cmd, format);
} else {
return Response.error('Invalid master password.');
}
}
async saveFile(csv: string, cmd: program.Command): Promise<Response> {
async saveFile(csv: string, cmd: program.Command, format: string): Promise<Response> {
try {
const filePath = await CliUtils.saveFile(csv, cmd.output, this.exportService.getFileName());
const filePath = await CliUtils.saveFile(csv, cmd.output, this.exportService.getFileName(null, format));
const res = new MessageResponse('Saved ' + filePath, null);
res.raw = filePath;
return Response.success(res);