From 492bc32aa31c5957bd3d6b57ac7f1d144bcfbfa7 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 10 Oct 2019 21:23:56 -0400 Subject: [PATCH] get config value when value not provided --- src/commands/config.command.ts | 16 +++++++++++----- src/program.ts | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/commands/config.command.ts b/src/commands/config.command.ts index 28ca591658..d9bdf57bd4 100644 --- a/src/commands/config.command.ts +++ b/src/commands/config.command.ts @@ -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 { + 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); } } diff --git a/src/program.ts b/src/program.ts index a42ab65096..a5d09dcbf4 100644 --- a/src/program.ts +++ b/src/program.ts @@ -576,7 +576,7 @@ export class Program extends BaseProgram { }); program - .command('config ') + .command('config [value]') .description('Configure CLI settings.') .on('--help', () => { writeLn('\n Settings:');