mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-04 18:37:45 +01:00
get config value when value not provided
This commit is contained in:
parent
7205b8c189
commit
492bc32aa3
@ -4,6 +4,7 @@ import { EnvironmentService } from 'jslib/abstractions/environment.service';
|
|||||||
|
|
||||||
import { Response } from 'jslib/cli/models/response';
|
import { Response } from 'jslib/cli/models/response';
|
||||||
import { MessageResponse } from 'jslib/cli/models/response/messageResponse';
|
import { MessageResponse } from 'jslib/cli/models/response/messageResponse';
|
||||||
|
import { StringResponse } from 'jslib/cli/models/response/stringResponse';
|
||||||
|
|
||||||
export class ConfigCommand {
|
export class ConfigCommand {
|
||||||
constructor(private environmentService: EnvironmentService) { }
|
constructor(private environmentService: EnvironmentService) { }
|
||||||
@ -12,20 +13,25 @@ export class ConfigCommand {
|
|||||||
setting = setting.toLowerCase();
|
setting = setting.toLowerCase();
|
||||||
switch (setting) {
|
switch (setting) {
|
||||||
case 'server':
|
case 'server':
|
||||||
await this.setServer(value);
|
return await this.getOrSetServer(value);
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return Response.badRequest('Unknown setting.');
|
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);
|
url = (url === 'null' || url === 'bitwarden.com' || url === 'https://bitwarden.com' ? null : url);
|
||||||
await this.environmentService.setUrls({
|
await this.environmentService.setUrls({
|
||||||
base: url,
|
base: url,
|
||||||
});
|
});
|
||||||
|
const res = new MessageResponse('Saved setting `config`.', null);
|
||||||
|
return Response.success(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -576,7 +576,7 @@ export class Program extends BaseProgram {
|
|||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
.command('config <setting> <value>')
|
.command('config <setting> [value]')
|
||||||
.description('Configure CLI settings.')
|
.description('Configure CLI settings.')
|
||||||
.on('--help', () => {
|
.on('--help', () => {
|
||||||
writeLn('\n Settings:');
|
writeLn('\n Settings:');
|
||||||
|
Loading…
Reference in New Issue
Block a user