@@ -27,6 +29,7 @@ class ExerciseCreateCommand extends CommanderCommand {
...
@@ -27,6 +29,7 @@ class ExerciseCreateCommand extends CommanderCommand {
.option('-i, --members_id <ids...>','list of gitlab members ids (group\'s student) to add to the repository')
.option('-i, --members_id <ids...>','list of gitlab members ids (group\'s student) to add to the repository')
.option('-u, --members_username <usernames...>','list of gitlab members username (group\'s student) to add to the repository')
.option('-u, --members_username <usernames...>','list of gitlab members username (group\'s student) to add to the repository')
.option('-c, --clone [string]','automatically clone the repository (SSH required) in the specified directory (this will create a subdirectory with the assignment name)')
.option('-c, --clone [string]','automatically clone the repository (SSH required) in the specified directory (this will create a subdirectory with the assignment name)')
.addOption(newOption('-f, --force','don\'t ask for choice if there are already exercises for this assignment and try to create a new one anyway'))
.action(this.commandAction.bind(this));
.action(this.commandAction.bind(this));
}
}
...
@@ -70,25 +73,85 @@ class ExerciseCreateCommand extends CommanderCommand {
...
@@ -70,25 +73,85 @@ class ExerciseCreateCommand extends CommanderCommand {
}).start().info();
}).start().info();
};
};
oraInfo(TextStyle.WARNING(`You already created ${this.assignment.myExercises.length} exercises for this assignment:`),4);
oraInfo(TextStyle.WARNING(`You already created ${this.assignment.myExercises.length} exercise${this.assignment.myExercises.length>1?'s':''} for this assignment${this.assignment.myExercises.length>=ClientsSharedConfig.exercise.maxPerAssignment?' (which is the limit)':''}:`),4);
oraInfo(`${TextStyle.LIST_ITEM_NAME('Members:')}${exercise.members?.map(member=>member.gitlabUsername).join(', ')??'There is only you'}`);
oraInfo(`${TextStyle.LIST_ITEM_NAME('Members:')}${exercise.members?.map(member=>member.gitlabUsername).join(', ')??'There is only you'}`);
}
constconfirm:boolean=(awaitinquirer.prompt({
presets.push({
name:'confirm',
name:`Delete "${exercise.name}" and create a new one.`,
prefix:'',
value:{
message:`${TextStyle.QUESTION('?')} You already created ${this.assignment.myExercises.length} exercises for this assignment (see above). Are you sure you want to create a new one?`,
delete:exercise.id,
type:'confirm',
deleteAll:false,
default:false
create:true
})).confirm;
}
});
}
if (!confirm){
if (!options.force){
thrownewError();
presets.push(newinquirer.Separator());
if (this.assignment.myExercises.length>1){
presets.push({
name:`Delete all existing exercises for this assignment and create a new one.`,
value:{
delete:false,
deleteAll:true,
create:true
}
},newinquirer.Separator());
}
if (this.assignment.myExercises.length<ClientsSharedConfig.exercise.maxPerAssignment){
message:`You already created ${this.assignment.myExercises.length} exercise${this.assignment.myExercises.length>1?'s':''}${this.assignment.myExercises.length>=ClientsSharedConfig.exercise.maxPerAssignment?' (which is the limit)':''} for this assignment (see above). What do you want to do?`,
type:'list',
pageSize:1000,
choices:presets
})).creationChoice;
if (creationChoice.delete||creationChoice.deleteAll){
console.log(TextStyle.BLOCK(`Please wait while we are deleting the exercise${creationChoice.deleteAll?'s':''}...`));