1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-30 08:10:34 +01:00

config command

This commit is contained in:
Kyle Spearrin 2018-05-17 00:07:44 -04:00
parent 7eb0c00a87
commit 02886b266c
2 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,31 @@
import * as program from 'commander';
import { EnvironmentService } from 'jslib/abstractions/environment.service';
import { Response } from '../models/response';
import { MessageResponse } from '../models/response/messageResponse';
export class ConfigCommand {
constructor(private environmentService: EnvironmentService) { }
async run(setting: string, value: string, cmd: program.Command): Promise<Response> {
setting = setting.toLowerCase();
switch (setting) {
case 'server':
await this.setServer(value);
break;
default:
return Response.badRequest('Unknown setting.');
}
const res = new MessageResponse('Saved setting `' + setting + '`.', null);
return Response.success(res);
}
private async setServer(url: string) {
url = (url === 'null' || url === 'bitwarden.com' || url === 'https://bitwarden.com' ? null : url);
await this.environmentService.setUrls({
base: url,
});
}
}

View File

@ -3,6 +3,7 @@ import * as program from 'commander';
import { Main } from './bw';
import { ConfigCommand } from './commands/config.command';
import { CreateCommand } from './commands/create.command';
import { DeleteCommand } from './commands/delete.command';
import { EditCommand } from './commands/edit.command';
@ -386,6 +387,26 @@ export class Program {
this.processResponse(response);
});
program
.command('config <setting> <value>')
.description('Configure settings.')
.on('--help', () => {
writeLn('\n Settings:');
writeLn('');
writeLn(' server - On-premise hosted installation URL.');
writeLn('');
writeLn(' Examples:');
writeLn('');
writeLn(' bw config server https://bw.company.com');
writeLn(' bw config server bitwarden.com');
writeLn('');
})
.action(async (setting, value, cmd) => {
const command = new ConfigCommand(this.main.environmentService);
const response = await command.run(setting, value, cmd);
this.processResponse(response);
});
program
.command('update')
.description('Check for updates.')