diff --git a/NodeApp/src/commander/exercise/ExerciseCommand.ts b/NodeApp/src/commander/exercise/ExerciseCommand.ts index bdc5fa4a473926c10887f046b9a29535e10a9977..224af4e5e7d770b6a2aa09eeaa797b5a640f8ce4 100644 --- a/NodeApp/src/commander/exercise/ExerciseCommand.ts +++ b/NodeApp/src/commander/exercise/ExerciseCommand.ts @@ -3,8 +3,8 @@ import ExerciseCreateCommand from './subcommands/ExerciseCreateCommand.js'; import ExerciseRunCommand from './subcommands/ExerciseRunCommand.js'; import ExerciseCorrectionCommand from './subcommands/ExerciseCorrectionCommand.js'; import ExerciseDeleteCommand from './subcommands/ExerciseDeleteCommand'; -import ExerciseListCommand from "./subcommands/ExerciseListCommand"; -import ExerciseResultCommand from "./subcommands/ExerciseResultCommand"; +import ExerciseSearchCommand from './subcommands/ExerciseSearchCommand'; +import ExerciseInfoCommand from './subcommands/ExerciseInfoCommand'; import ExerciseSummaryCommand from "./subcommands/ExerciseSummaryCommand"; @@ -22,7 +22,7 @@ class ExerciseCommand extends CommanderCommand { ExerciseDeleteCommand.registerOnCommand(this.command); ExerciseCorrectionCommand.registerOnCommand(this.command); ExerciseListCommand.registerOnCommand(this.command); - ExerciseResultCommand.registerOnCommand(this.command); + ExerciseInfoCommand.registerOnCommand(this.command); ExerciseSummaryCommand.registerOnCommand(this.command); } diff --git a/NodeApp/src/commander/exercise/subcommands/ExerciseInfoCommand.ts b/NodeApp/src/commander/exercise/subcommands/ExerciseInfoCommand.ts new file mode 100644 index 0000000000000000000000000000000000000000..944033b9eeeba433c9f299b636e03531bca54f7e --- /dev/null +++ b/NodeApp/src/commander/exercise/subcommands/ExerciseInfoCommand.ts @@ -0,0 +1,54 @@ +import CommanderCommand from '../../CommanderCommand'; +import AccessesHelper from '../../../helpers/AccessesHelper'; +import TextStyle from '../../../types/TextStyle'; +import ExerciseHelper from '../../../helpers/Dojo/ExerciseHelper'; +import Exercise from '../../../sharedByClients/models/Exercise'; +import DojoBackendManager from '../../../managers/DojoBackendManager'; +import ora from 'ora'; +import Config from '../../../config/Config'; + + +class ExerciseInfoCommand extends CommanderCommand { + protected commandName: string = 'info'; + + protected defineCommand(): void { + this.command + .description('delete an exercise') + .argument('id or url', 'id or url of the exercise') + .action(this.commandAction.bind(this)); + } + + private async dataRetrieval(exerciseIdOrUrl: string): Promise<Exercise> { + console.log(TextStyle.BLOCK('Please wait while we verify and retrieve data...')); + + await AccessesHelper.checkStudent(); + + + // Fetch exercise + const exercisesGetSpinner: ora.Ora = ora({ + text : `Checking exercise`, + indent: 4 + }).start(); + + const exercise = await DojoBackendManager.getExercise(exerciseIdOrUrl); + + if ( !exercise ) { + exercisesGetSpinner.fail(`Exercise not found`); + throw new Error(); + } + + exercisesGetSpinner.succeed(`Exercise fetched successfully`); + + return exercise; + } + + protected async commandAction(exerciseIdOrUrl: string): Promise<void> { + try { + const exercise = await this.dataRetrieval(exerciseIdOrUrl); + return ExerciseHelper.displayDetails(exercise, Config.interactiveMode); + } catch ( e ) { /* Do nothing */ } + } +} + + +export default new ExerciseInfoCommand();