|
1 | 1 | package fi.helsinki.cs.tmc.cli.command; |
2 | 2 |
|
| 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 | + |
3 | 7 | import fi.helsinki.cs.tmc.cli.command.core.AbstractCommand; |
4 | 8 | import fi.helsinki.cs.tmc.cli.command.core.Command; |
| 9 | +import fi.helsinki.cs.tmc.cli.io.Color; |
5 | 10 | import fi.helsinki.cs.tmc.cli.io.Io; |
6 | 11 | import fi.helsinki.cs.tmc.cli.tmcstuff.CourseInfo; |
7 | 12 | import fi.helsinki.cs.tmc.cli.tmcstuff.CourseInfoIo; |
@@ -53,13 +58,13 @@ public void run(CommandLine args, Io io) { |
53 | 58 | if (workDir.getExerciseNames().size() == 1 && stringArgs.length == 0) { |
54 | 59 | String currentExercise = workDir.getExerciseNames().get(0); |
55 | 60 | exercise = info.getExercise(currentExercise); |
56 | | - printExerciseDetails(); |
| 61 | + printOneExercise(args.hasOption("a")); |
57 | 62 | return; |
58 | 63 |
|
59 | 64 | } else if (stringArgs.length != 0) { |
60 | 65 | if (info.getExercise(stringArgs[0]) != null) { |
61 | 66 | exercise = info.getExercise(stringArgs[0]); |
62 | | - printExerciseDetails(); |
| 67 | + printOneExercise(args.hasOption("a")); |
63 | 68 | return; |
64 | 69 |
|
65 | 70 | } else { |
@@ -109,11 +114,32 @@ private void printCourseDetails() { |
109 | 114 | io.println("CometUrl: " + course.getCometUrl()); |
110 | 115 | } |
111 | 116 |
|
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 | + } |
117 | 143 | } |
118 | 144 |
|
119 | 145 | private void printExercises(boolean showAll) { |
@@ -169,4 +195,13 @@ private void printExercise(Exercise exercise) { |
169 | 195 | io.println(" Checksum: " + exercise.getChecksum()); |
170 | 196 | io.println(""); |
171 | 197 | } |
| 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 | + } |
172 | 207 | } |
0 commit comments