1
0
mirror of https://github.com/bitwarden/cli synced 2025-12-16 00:03:23 +00:00
Files
cli/src/commands/sync.command.ts
Fredrik Ekre 179a6e8a96 SyncCommand: Pass allowThrowOnError to fullSync
This intends to make explicit calls to bw sync
throw if the syncing can not be performed,
fixes https://github.com/bitwarden/cli/issues/129.
2020-11-20 16:17:09 +01:00

32 lines
1.1 KiB
TypeScript

import * as program from 'commander';
import { SyncService } from 'jslib/abstractions/sync.service';
import { Response } from 'jslib/cli/models/response';
import { MessageResponse } from 'jslib/cli/models/response/messageResponse';
import { StringResponse } from 'jslib/cli/models/response/stringResponse';
export class SyncCommand {
constructor(private syncService: SyncService) { }
async run(cmd: program.Command): Promise<Response> {
if (cmd.last || false) {
return await this.getLastSync();
}
try {
const result = await this.syncService.fullSync(cmd.force || false, true);
const res = new MessageResponse('Syncing complete.', null);
return Response.success(res);
} catch (e) {
return Response.error('Syncing failed: ' + e.toString());
}
}
private async getLastSync() {
const lastSyncDate = await this.syncService.getLastSync();
const res = new StringResponse(lastSyncDate == null ? null : lastSyncDate.toISOString());
return Response.success(res);
}
}