Select Git revision
SessionAppLoginCommand.ts

michael.minelli authored
SessionAppLoginCommand.ts 1.82 KiB
import chalk from 'chalk';
import CommanderCommand from '../../CommanderCommand';
import inquirer from 'inquirer';
import SessionManager from '../../../managers/SessionManager';
class SessionAppLoginCommand extends CommanderCommand {
protected commandName: string = 'login';
private static _instance: SessionAppLoginCommand;
private constructor() { super(); }
public static get instance(): SessionAppLoginCommand {
if ( !SessionAppLoginCommand._instance ) {
SessionAppLoginCommand._instance = new SessionAppLoginCommand();
}
return SessionAppLoginCommand._instance;
}
protected defineCommand() {
this.command
.description('login into the application')
.requiredOption('-u, --user <string>', '[required] username to use when connecting to server')
.option('-p, --password <string>', 'password to use when connecting to server. If password is not given it\'s asked')
.action(this.commandAction.bind(this));
}
protected async commandAction(options: any): Promise<void> {
if ( !options.password ) {
options.password = (await inquirer.prompt({
type : 'password',
name : 'password',
message: 'Please enter your password',
mask : ''
})).password;
}
console.log(chalk.cyan('Please wait while we are logging in you to Dojo...'));
await SessionManager.login(options.user, options.password);
SessionManager.checkPermissions(true, 4);
}
}
export default SessionAppLoginCommand.instance;