import chalk            from 'chalk';
import CommanderCommand from '../../CommanderCommand';
import SessionManager   from '../../../managers/SessionManager';


class AuthLoginCommand extends CommanderCommand {
    protected commandName: string = 'login';

    protected defineCommand() {
        this.command
        .description('login to Dojo')
        .option('-c, --cli', 'proceed to the login in headless mode (do not try to open web browser).')
        .action(this.commandAction.bind(this));
    }

    protected async commandAction(options: { cli: boolean }): Promise<void> {
        try {
            console.log(chalk.cyan('Please wait while we login you into Dojo...'));
            await SessionManager.login(options.cli);
        } catch ( error ) { /* empty */ }
    }
}


export default new AuthLoginCommand();