get config value when value not provided

This commit is contained in:
Kyle Spearrin 2019-10-10 21:23:56 -04:00
parent 7205b8c189
commit 492bc32aa3
2 changed files with 12 additions and 6 deletions

View File

@ -4,6 +4,7 @@ import { EnvironmentService } from 'jslib/abstractions/environment.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 ConfigCommand {
constructor(private environmentService: EnvironmentService) { }
@ -12,20 +13,25 @@ export class ConfigCommand {
setting = setting.toLowerCase();
switch (setting) {
case 'server':
await this.setServer(value);
break;
return await this.getOrSetServer(value);
default:
return Response.badRequest('Unknown setting.');
}
const res = new MessageResponse('Saved setting `' + setting + '`.', null);
return Response.success(res);
}
private async setServer(url: string) {
private async getOrSetServer(url: string): Promise<Response> {
if (url == null || url.trim() === '') {
const baseUrl = this.environmentService.baseUrl;
const stringRes = new StringResponse(baseUrl == null ? 'https://bitwarden.com' : baseUrl);
return Response.success(stringRes);
}
url = (url === 'null' || url === 'bitwarden.com' || url === 'https://bitwarden.com' ? null : url);
await this.environmentService.setUrls({
base: url,
});
const res = new MessageResponse('Saved setting `config`.', null);
return Response.success(res);
}
}

View File

@ -576,7 +576,7 @@ export class Program extends BaseProgram {
});
program
.command('config <setting> <value>')
.command('config <setting> [value]')
.description('Configure CLI settings.')
.on('--help', () => {
writeLn('\n Settings:');