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

Commit ee39124

Browse files
committed
exercise info now looks better and has option -a
1 parent a821354 commit ee39124

1 file changed

Lines changed: 42 additions & 7 deletions

File tree

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

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package fi.helsinki.cs.tmc.cli.command;
22

3+
import static fi.helsinki.cs.tmc.cli.io.Color.AnsiColor.ANSI_BLUE;
4+
import static fi.helsinki.cs.tmc.cli.io.Color.AnsiColor.ANSI_GREEN;
5+
import static fi.helsinki.cs.tmc.cli.io.Color.AnsiColor.ANSI_RED;
6+
37
import fi.helsinki.cs.tmc.cli.command.core.AbstractCommand;
48
import fi.helsinki.cs.tmc.cli.command.core.Command;
9+
import fi.helsinki.cs.tmc.cli.io.Color;
510
import fi.helsinki.cs.tmc.cli.io.Io;
611
import fi.helsinki.cs.tmc.cli.tmcstuff.CourseInfo;
712
import fi.helsinki.cs.tmc.cli.tmcstuff.CourseInfoIo;
@@ -53,13 +58,13 @@ public void run(CommandLine args, Io io) {
5358
if (workDir.getExerciseNames().size() == 1 && stringArgs.length == 0) {
5459
String currentExercise = workDir.getExerciseNames().get(0);
5560
exercise = info.getExercise(currentExercise);
56-
printExerciseDetails();
61+
printOneExercise(args.hasOption("a"));
5762
return;
5863

5964
} else if (stringArgs.length != 0) {
6065
if (info.getExercise(stringArgs[0]) != null) {
6166
exercise = info.getExercise(stringArgs[0]);
62-
printExerciseDetails();
67+
printOneExercise(args.hasOption("a"));
6368
return;
6469

6570
} else {
@@ -109,11 +114,32 @@ private void printCourseDetails() {
109114
io.println("CometUrl: " + course.getCometUrl());
110115
}
111116

112-
private void printExerciseDetails() {
113-
io.println(exercise.getName());
114-
io.println("Completed: " + exercise.isCompleted());
115-
io.println("Attempted: " + exercise.isAttempted());
116-
io.println("Deadline: " + exercise.getDeadline());
117+
private void printOneExercise(boolean showAll) {
118+
if (showAll) {
119+
printExercise(exercise);
120+
} else {
121+
printExerciseShort();
122+
}
123+
}
124+
125+
private void printExerciseShort() {
126+
io.println("Exercise: " + exercise.getName());
127+
io.println("Deadline: " + getDeadline(exercise));
128+
io.println(formatString("completed", exercise.isCompleted()));
129+
if (!exercise.isCompleted() && exercise.isAttempted()) {
130+
io.println(Color.colorString("attempted", ANSI_BLUE));
131+
}
132+
if (exercise.requiresReview()) {
133+
io.println(formatString("reviewed", exercise.isReviewed()));
134+
}
135+
}
136+
137+
private String formatString(String string, boolean color) {
138+
if (color) {
139+
return Color.colorString(string, ANSI_GREEN);
140+
} else {
141+
return Color.colorString("not " + string, ANSI_RED);
142+
}
117143
}
118144

119145
private void printExercises(boolean showAll) {
@@ -169,4 +195,13 @@ private void printExercise(Exercise exercise) {
169195
io.println(" Checksum: " + exercise.getChecksum());
170196
io.println("");
171197
}
198+
199+
private String getDeadline(Exercise exercise) {
200+
String deadline = exercise.getDeadline();
201+
if (deadline == null) {
202+
return "not available";
203+
}
204+
deadline = deadline.substring(0, 19);
205+
return deadline.replace("T", " at ");
206+
}
172207
}

0 commit comments

Comments
 (0)