From 39cac1b06dd02431b483d314aa83e6e3833c9725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Minelli?= <git@minelli.swiss> Date: Tue, 25 Mar 2025 14:51:06 +0100 Subject: [PATCH] Exercise*Command => Use helper for common functions --- .../subcommands/ExerciseCreateCommand.ts | 24 +++---------------- .../subcommands/ExerciseDeleteCommand.ts | 16 ++++--------- .../subcommands/ExerciseSearchCommand.ts | 9 +++---- 3 files changed, 13 insertions(+), 36 deletions(-) diff --git a/NodeApp/src/commander/exercise/subcommands/ExerciseCreateCommand.ts b/NodeApp/src/commander/exercise/subcommands/ExerciseCreateCommand.ts index 16b70b7..c354b01 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 2ec20cd..f974a0b 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 39c3cb7..9c6183c 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 -- GitLab