1
0
mirror of https://github.com/bitwarden/directory-connector synced 2025-12-11 13:53:22 +00:00

base cli program and sync command

This commit is contained in:
Kyle Spearrin
2019-03-16 11:27:16 -04:00
parent a847339d72
commit 7cc941cc84
5 changed files with 66 additions and 102 deletions

View File

@@ -1,12 +1,13 @@
import * as program from 'commander';
import { EnvironmentService } from 'jslib/abstractions/environment.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { Response } from 'jslib/cli/models/response';
import { MessageResponse } from 'jslib/cli/models/response/messageResponse';
export class ConfigCommand {
constructor(private environmentService: EnvironmentService) { }
constructor(private environmentService: EnvironmentService, private i18nService: I18nService) { }
async run(setting: string, value: string, cmd: program.Command): Promise<Response> {
setting = setting.toLowerCase();
@@ -18,7 +19,7 @@ export class ConfigCommand {
return Response.badRequest('Unknown setting.');
}
const res = new MessageResponse('Saved setting `' + setting + '`.', null);
const res = new MessageResponse(this.i18nService.t('savedSetting', setting), null);
return Response.success(res);
}

View File

@@ -0,0 +1,25 @@
import * as program from 'commander';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { SyncService } from '../services/sync.service';
import { Response } from 'jslib/cli/models/response';
import { MessageResponse } from 'jslib/cli/models/response/messageResponse';
export class SyncCommand {
constructor(private syncService: SyncService, private i18nService: I18nService) { }
async run(cmd: program.Command): Promise<Response> {
try {
const result = await this.syncService.sync(false, false);
const groupCount = result[0] != null ? result[0].length : 0;
const userCount = result[1] != null ? result[1].length : 0;
const res = new MessageResponse(this.i18nService.t('syncingComplete'),
this.i18nService.t('syncCounts', groupCount.toString(), userCount.toString()));
return Response.success(res);
} catch (e) {
return Response.error(e);
}
}
}