bitwarden-estensione-browser/src/program.ts

84 lines
2.5 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';
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) => {
console.log('Syncing...');
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.')
.action((object, cmd) => {
console.log('Listing...');
console.log(object);
});
program
.command('get <object> <id>')
.description('Get an object.')
.action((object, id, cmd) => {
console.log('Getting...');
console.log(object);
console.log(id);
});
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);
}
}