diff --git a/NodeApp/src/commander/exercise/subcommands/ExerciseCreateCommand.ts b/NodeApp/src/commander/exercise/subcommands/ExerciseCreateCommand.ts index 16b70b79064d215c89e112b89c9b14c5e00ceeed..c354b0100d4dd29e9dc28ad8fcc70d55d488ec12 100644 --- a/NodeApp/src/commander/exercise/subcommands/ExerciseCreateCommand.ts +++ b/NodeApp/src/commander/exercise/subcommands/ExerciseCreateCommand.ts @@ -10,6 +10,7 @@ import inquirer from 'inquirer'; import Config from '../../../config/Config'; import ClientsSharedConfig from '../../../sharedByClients/config/ClientsSharedConfig'; import { Option } from 'commander'; +import ExerciseHelper from '../../../helpers/Dojo/ExerciseHelper'; type CommandOptions = { assignment: string, members_id?: Array<number>, members_username?: Array<string>, clone?: string | boolean, force?: boolean }; @@ -161,26 +162,7 @@ class ExerciseCreateCommand extends CommanderCommand { this.exercise = await DojoBackendManager.createExercise(this.assignment!.name, this.members!); - const oraInfo = (message: string) => { - ora({ - text : message, - indent: 4 - }).start().info(); - }; - - oraInfo(`${ TextStyle.LIST_ITEM_NAME('Id:') } ${ this.exercise.id }`); - oraInfo(`${ TextStyle.LIST_ITEM_NAME('Name:') } ${ this.exercise.name }`); - oraInfo(`${ TextStyle.LIST_ITEM_NAME('Web URL:') } ${ this.exercise.gitlabCreationInfo.web_url }`); - oraInfo(`${ TextStyle.LIST_ITEM_NAME('HTTP Repo:') } ${ this.exercise.gitlabCreationInfo.http_url_to_repo }`); - oraInfo(`${ TextStyle.LIST_ITEM_NAME('SSH Repo:') } ${ this.exercise.gitlabCreationInfo.ssh_url_to_repo }`); - } - - private async cloneRepository(options: CommandOptions) { - if ( options.clone ) { - console.log(TextStyle.BLOCK('Please wait while we are cloning the repository...')); - - await Config.gitlabManager.cloneRepository(options.clone, this.exercise.gitlabCreationInfo.ssh_url_to_repo, `DojoExercise_${ this.exercise.assignmentName }`, true, 0); - } + await ExerciseHelper.displayDetails(this.exercise); } @@ -188,7 +170,7 @@ class ExerciseCreateCommand extends CommanderCommand { try { await this.dataRetrieval(options); await this.createExercise(); - await this.cloneRepository(options); + await ExerciseHelper.clone(this.exercise, options.clone ?? false); } catch ( e ) { /* Do nothing */ } } } diff --git a/NodeApp/src/commander/exercise/subcommands/ExerciseDeleteCommand.ts b/NodeApp/src/commander/exercise/subcommands/ExerciseDeleteCommand.ts index 2ec20cdfd13b93306de1bf9095adc9c6d40abb5c..f974a0bbdf75bf42a47abf29f8e0d949e94820a8 100644 --- a/NodeApp/src/commander/exercise/subcommands/ExerciseDeleteCommand.ts +++ b/NodeApp/src/commander/exercise/subcommands/ExerciseDeleteCommand.ts @@ -1,7 +1,7 @@ -import CommanderCommand from '../../CommanderCommand'; -import DojoBackendManager from '../../../managers/DojoBackendManager'; -import AccessesHelper from '../../../helpers/AccessesHelper'; -import TextStyle from '../../../types/TextStyle'; +import CommanderCommand from '../../CommanderCommand'; +import AccessesHelper from '../../../helpers/AccessesHelper'; +import TextStyle from '../../../types/TextStyle'; +import ExerciseHelper from '../../../helpers/Dojo/ExerciseHelper'; class ExerciseDeleteCommand extends CommanderCommand { @@ -20,16 +20,10 @@ class ExerciseDeleteCommand extends CommanderCommand { await AccessesHelper.checkStudent(); } - private async deleteExercise(exerciseIdOrUrl: string) { - console.log(TextStyle.BLOCK('Please wait while we are deleting the exercise...')); - - await DojoBackendManager.deleteExercise(exerciseIdOrUrl); - } - protected async commandAction(exerciseIdOrUrl: string): Promise<void> { try { await this.dataRetrieval(); - await this.deleteExercise(exerciseIdOrUrl); + await ExerciseHelper.delete(exerciseIdOrUrl); } catch ( e ) { /* Do nothing */ } } } diff --git a/NodeApp/src/commander/exercise/subcommands/ExerciseSearchCommand.ts b/NodeApp/src/commander/exercise/subcommands/ExerciseSearchCommand.ts index 39c3cb7f9f2b61e69e93138cbfa17f2e160faa22..9c6183cba27bf019c5b7a94c0ca066a1691943e7 100644 --- a/NodeApp/src/commander/exercise/subcommands/ExerciseSearchCommand.ts +++ b/NodeApp/src/commander/exercise/subcommands/ExerciseSearchCommand.ts @@ -17,8 +17,9 @@ import Config from '../../../config/Config'; type CommandOptions = { all: boolean, name: string, teacher: string }; -class ExerciseListCommand extends CommanderCommand { - protected commandName: string = 'list'; +class ExerciseSearchCommand extends CommanderCommand { + protected commandName: string = 'search'; + protected aliasNames: string[] = [ 'list' ]; protected teachers: User[] = []; @@ -106,7 +107,7 @@ class ExerciseListCommand extends CommanderCommand { }, new inquirer.Separator(), { name : 'Exit', value: 'exit' - } ] + }, new inquirer.Separator() ] } ])).action; switch ( action ) { @@ -309,4 +310,4 @@ class ExerciseListCommand extends CommanderCommand { } -export default new ExerciseListCommand(); \ No newline at end of file +export default new ExerciseSearchCommand(); \ No newline at end of file