diff --git a/NodeApp/src/commander/CommanderApp.ts b/NodeApp/src/commander/CommanderApp.ts new file mode 100644 index 0000000000000000000000000000000000000000..075d672d3e4ef81c7feb937ba7daef5505e806b2 --- /dev/null +++ b/NodeApp/src/commander/CommanderApp.ts @@ -0,0 +1,61 @@ +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 diff --git a/NodeApp/src/main.ts b/NodeApp/src/main.ts index fd781d9bfb1aae9339412d3b7686a07ba5e4f82a..af3ecf8da4bbac12209edee52124ad1680cf3e78 100644 --- a/NodeApp/src/main.ts +++ b/NodeApp/src/main.ts @@ -2,9 +2,12 @@ // ATTENTION : This line MUST be the first of this file require('dotenv').config(); -import HttpManager from './managers/HttpManager'; -import LocalConfig from './Config/LocalConfig/LocalConfig'; +import CommanderApp from './commander/CommanderApp'; +import HttpManager from './managers/HttpManager'; +import LocalConfig from './Config/LocalConfig/LocalConfig'; LocalConfig.loadConfig(); -HttpManager.registerAxiosInterceptor(); \ No newline at end of file +HttpManager.registerAxiosInterceptor(); + +new CommanderApp(); \ No newline at end of file