1
0
mirror of https://github.com/bitwarden/cli synced 2025-12-24 04:03:15 +00:00

serve command (#451)

This commit is contained in:
Kyle Spearrin
2022-01-19 10:45:14 -05:00
committed by GitHub
parent 84a0bfb07c
commit 922cd1dc54
26 changed files with 2091 additions and 332 deletions

View File

@@ -1,21 +1,22 @@
import * as program from "commander";
import { SyncService } from "jslib-common/abstractions/sync.service";
import { Response } from "jslib-node/cli/models/response";
import { MessageResponse } from "jslib-node/cli/models/response/messageResponse";
import { StringResponse } from "jslib-node/cli/models/response/stringResponse";
import { CliUtils } from "src/utils";
export class SyncCommand {
constructor(private syncService: SyncService) {}
async run(options: program.OptionValues): Promise<Response> {
if (options.last || false) {
async run(cmdOptions: Record<string, any>): Promise<Response> {
const normalizedOptions = new Options(cmdOptions);
if (normalizedOptions.last) {
return await this.getLastSync();
}
try {
const result = await this.syncService.fullSync(options.force || false, true);
const result = await this.syncService.fullSync(normalizedOptions.force, true);
const res = new MessageResponse("Syncing complete.", null);
return Response.success(res);
} catch (e) {
@@ -29,3 +30,13 @@ export class SyncCommand {
return Response.success(res);
}
}
class Options {
last: boolean;
force: boolean;
constructor(passedOptions: Record<string, any>) {
this.last = CliUtils.convertBooleanOption(passedOptions.last);
this.force = CliUtils.convertBooleanOption(passedOptions.force);
}
}