Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 9495932

Browse files
author
juvester
committed
Don't try to download locked exercises by default
1 parent b50c380 commit 9495932

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/main/java/fi/helsinki/cs/tmc/cli/command/DownloadExercisesCommand.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void getOptions(Options options) {
2929
options.addOption("a", "all", false,
3030
"Download all available exercises, including previously completed");
3131

32-
// Not implemented in tmc-core yet
32+
// Download old submissions. Not implemented in tmc-core yet
3333
//options.addOption("c", "completed", false, "Download previously completed exercises");
3434
}
3535

@@ -68,7 +68,13 @@ public void run(CommandLine args, Io io) {
6868
TmcCliProgressObserver progobs = new TmcCliProgressObserver(io, color1, color2);
6969

7070
List<Exercise> exercises = TmcUtil.downloadExercises(core, filtered, progobs);
71-
io.println(exercises.toString());
71+
if (exercises.isEmpty()) {
72+
io.println("Failed to download exercises");
73+
return;
74+
} else if (exercises.size() != filtered.size()) {
75+
io.println(Color.colorString("Some exercises could not be downloaded",
76+
Color.AnsiColor.ANSI_RED));
77+
}
7278

7379
Path configFile = app.getWorkDir().getWorkingDirectory()
7480
.resolve(stringArgs[0])
@@ -85,7 +91,9 @@ protected List<Exercise> getFilteredExercises(Course course, CommandLine args) {
8591

8692
List<Exercise> filtered = new ArrayList<>();
8793
for (Exercise exercise : course.getExercises()) {
88-
if (!exercise.isCompleted()) {
94+
// Teachers may get a list of locked exercises but core still refuses to
95+
// download them. Filter locked exercises out.
96+
if (!exercise.isCompleted() && !exercise.isLocked()) {
8997
filtered.add(exercise);
9098
}
9199
}

src/test/java/fi/helsinki/cs/tmc/cli/command/DownloadExercisesCommandTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.junit.Before;
3030
import org.junit.Test;
3131

32+
import java.io.File;
3233
import java.io.IOException;
3334
import java.nio.file.Path;
3435
import java.nio.file.Paths;
@@ -138,7 +139,9 @@ public List<Exercise> call() throws Exception {
138139

139140
String[] args = {"download", "course1"};
140141
app.run(args);
141-
assertTrue(testIo.out().contains("exerciseName"));
142+
143+
File courseJson = tempDir.resolve("course1").resolve(".tmc.json").toFile();
144+
assertTrue(courseJson.exists());
142145
}
143146

144147
@Test

0 commit comments

Comments
 (0)