Skip to content
Snippets Groups Projects
Commit c6edf7a6 authored by michael.minelli's avatar michael.minelli
Browse files

Add Commander command line with session functions

parent 7c1b05e3
No related branches found
No related tags found
No related merge requests found
Pipeline #25035 passed
import { Command } from 'commander';
import prompt from 'prompt';
import colors from '@colors/colors/safe';
import SessionManager from '../managers/SessionManager';
import axios from 'axios';
import HttpManager from '../managers/HttpManager';
import logger from '../shared/logging/WinstonLogger';
class CommanderApp {
program = new Command();
constructor() {
this.program
.name('Dojo CLI')
.description('CLI for the Dojo application')
.version('1.0.0Ɑ');
this.loginCommand();
this.testSessionCommand();
this.program.parse();
}
loginCommand() {
this.program.command('login')
.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((options) => {
if ( !options.password ) {
prompt.get({
properties: {
password: {
description: colors.cyan('Please enter your password'),
required : true,
hidden : true
}
}
}, (err, result) => {
options.password = result.password;
});
}
SessionManager.login(options.user, options.password);
});
}
testSessionCommand() {
this.program.command('test-session')
.description('Test availability of session')
.action(async (options) => {
const response = await axios.get(HttpManager.TEST_SESSION_URL);
logger.info('Session is valid');
});
}
}
export default CommanderApp;
\ No newline at end of file
...@@ -2,9 +2,12 @@ ...@@ -2,9 +2,12 @@
// ATTENTION : This line MUST be the first of this file // ATTENTION : This line MUST be the first of this file
require('dotenv').config(); require('dotenv').config();
import CommanderApp from './commander/CommanderApp';
import HttpManager from './managers/HttpManager'; import HttpManager from './managers/HttpManager';
import LocalConfig from './Config/LocalConfig/LocalConfig'; import LocalConfig from './Config/LocalConfig/LocalConfig';
LocalConfig.loadConfig(); LocalConfig.loadConfig();
HttpManager.registerAxiosInterceptor(); HttpManager.registerAxiosInterceptor();
new CommanderApp();
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment