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

88 lines
2.9 KiB
TypeScript
Raw Normal View History

2018-05-14 17:15:54 +02:00
import * as program from 'commander';
import { LoginCommand } from './commands/login.command';
import { SyncCommand } from './commands/sync.command';
2018-05-14 19:37:52 +02:00
import { ListCommand } from './commands/list.command';
import { GetCommand } from './commands/get.command';
2018-05-14 17:15:54 +02:00
import { Main } from './main';
export class Program {
constructor(private main: Main) { }
run() {
program
.version('1.0.0', '-v, --version');
program
.command('login <email> <password>')
.description('Log into a Bitwarden user account.')
.option('-m, --method <method>', '2FA method.')
.option('-c, --code <code>', '2FA code.')
.action(async (email: string, password: string, cmd: program.Command) => {
const command = new LoginCommand(this.main.authService);
await command.run(email, password, cmd);
2018-05-14 17:59:34 +02:00
process.exit();
2018-05-14 17:15:54 +02:00
});
program
.command('logout')
.description('Log out of the current Bitwarden user account.')
.action((cmd) => {
console.log('Logging out...');
2018-05-14 17:59:34 +02:00
process.exit();
2018-05-14 17:15:54 +02:00
});
program
.command('sync')
.description('Sync user\'s vault from server.')
.option('-f, --force', 'Force a full sync.')
.action(async (cmd) => {
const command = new SyncCommand(this.main.syncService);
await command.run(cmd);
2018-05-14 17:59:34 +02:00
process.exit();
2018-05-14 17:15:54 +02:00
});
program
.command('list <object>')
.description('List objects.')
2018-05-14 19:37:52 +02:00
.action(async (object, cmd) => {
const command = new ListCommand(this.main.cipherService, this.main.folderService,
this.main.collectionService);
await command.run(object, cmd);
process.exit();
2018-05-14 17:15:54 +02:00
});
program
.command('get <object> <id>')
.description('Get an object.')
2018-05-14 19:37:52 +02:00
.action(async (object, id, cmd) => {
const command = new GetCommand(this.main.cipherService, this.main.folderService,
this.main.collectionService, this.main.totpService);
await command.run(object, id, cmd);
process.exit();
2018-05-14 17:15:54 +02:00
});
program
.command('edit <object> <id>')
.description('Edit an object.')
.action((object, id, cmd) => {
console.log('Editing...');
console.log(object);
console.log(id);
});
program
.command('delete <object> <id>')
.description('Delete an object.')
.action((object, id, cmd) => {
console.log('Deleting...');
console.log(object);
console.log(id);
});
program
.parse(process.argv);
}
}