mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
export file format option
This commit is contained in:
2
jslib
2
jslib
Submodule jslib updated: 94f103c474...e7b5868aad
@@ -28,16 +28,17 @@ export class ExportCommand {
|
|||||||
const keyHash = await this.cryptoService.hashPassword(password, null);
|
const keyHash = await this.cryptoService.hashPassword(password, null);
|
||||||
const storedKeyHash = await this.cryptoService.getKeyHash();
|
const storedKeyHash = await this.cryptoService.getKeyHash();
|
||||||
if (storedKeyHash != null && keyHash != null && storedKeyHash === keyHash) {
|
if (storedKeyHash != null && keyHash != null && storedKeyHash === keyHash) {
|
||||||
const csv = await this.exportService.getExport('csv');
|
const format = cmd.format !== 'json' ? 'csv' : 'json';
|
||||||
return await this.saveFile(csv, cmd);
|
const csv = await this.exportService.getExport(format);
|
||||||
|
return await this.saveFile(csv, cmd, format);
|
||||||
} else {
|
} else {
|
||||||
return Response.error('Invalid master password.');
|
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 {
|
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);
|
const res = new MessageResponse('Saved ' + filePath, null);
|
||||||
res.raw = filePath;
|
res.raw = filePath;
|
||||||
return Response.success(res);
|
return Response.success(res);
|
||||||
|
|||||||
@@ -429,15 +429,21 @@ export class Program {
|
|||||||
|
|
||||||
program
|
program
|
||||||
.command('export [password]')
|
.command('export [password]')
|
||||||
.description('Export vault data to a CSV file.')
|
.description('Export vault data to a CSV or JSON file.')
|
||||||
.option('--output <output>', 'Output directory or filename.')
|
.option('--output <output>', 'Output directory or filename.')
|
||||||
|
.option('--format <format>', 'Export file format.')
|
||||||
.on('--help', () => {
|
.on('--help', () => {
|
||||||
writeLn('\n Examples:');
|
writeLn('\n Notes:');
|
||||||
|
writeLn('');
|
||||||
|
writeLn(' Valid formats are `csv` and `json`. Default format is `csv`.');
|
||||||
|
writeLn('');
|
||||||
|
writeLn(' Examples:');
|
||||||
writeLn('');
|
writeLn('');
|
||||||
writeLn(' bw export');
|
writeLn(' bw export');
|
||||||
writeLn(' bw export myPassword321');
|
writeLn(' bw export myPassword321');
|
||||||
|
writeLn(' bw export myPassword321 --format json');
|
||||||
writeLn(' bw export --output ./exp/bw.csv');
|
writeLn(' bw export --output ./exp/bw.csv');
|
||||||
writeLn(' bw export myPassword321 --output bw.csv');
|
writeLn(' bw export myPassword321 --output bw.json --format json');
|
||||||
writeLn('', true);
|
writeLn('', true);
|
||||||
})
|
})
|
||||||
.action(async (password, cmd) => {
|
.action(async (password, cmd) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user