2424@ Command (name = "download" , desc = "Download exercises for a specific course" )
2525public class DownloadExercisesCommand extends AbstractCommand {
2626
27+ private boolean showAll ;
28+
2729 @ Override
2830 public void getOptions (Options options ) {
2931 options .addOption ("a" , "all" , false ,
@@ -36,12 +38,14 @@ public void getOptions(Options options) {
3638 @ Override
3739 public void run (CommandLine args , Io io ) {
3840 String [] stringArgs = args .getArgs ();
39- if (stringArgs .length == 0 ) {
41+ if (stringArgs .length == 0 || stringArgs . length > 1 ) {
4042 io .println ("You must give course name as an argument." );
4143 io .println ("Usage: tmc download COURSE" );
4244 return ;
4345 }
4446
47+ showAll = args .hasOption ("a" );
48+
4549 Application app = getApp ();
4650 TmcCore core = app .getTmcCore ();
4751 WorkDir workDir = getApp ().getWorkDir ();
@@ -54,12 +58,13 @@ public void run(CommandLine args, Io io) {
5458 return ;
5559 }
5660
57- Course course = TmcUtil .findCourse (core , stringArgs [0 ]);
61+ String courseName = stringArgs [0 ];
62+ Course course = TmcUtil .findCourse (core , courseName );
5863 if (course == null ) {
5964 io .println ("Course doesn't exist." );
6065 return ;
6166 }
62- List <Exercise > filtered = getFilteredExercises (course , args );
67+ List <Exercise > filtered = getFilteredExercises (course );
6368 // todo: If -c switch, use core.downloadCompletedExercises() to download user's old
6469 // submissions. Not yet implemented in tmc-core.
6570
@@ -71,24 +76,38 @@ public void run(CommandLine args, Io io) {
7176 if (exercises == null ) {
7277 io .println ("Failed to download exercises" );
7378 return ;
74- } else if (exercises .isEmpty ()) {
75- io .println ("Course doesn't have any exercises." );
79+ }
7680
77- } else if (exercises .size () != filtered .size ()) {
78- io .println (Color .colorString ("Some exercises could not be downloaded" ,
79- Color .AnsiColor .ANSI_RED ));
81+ if (course .getExercises ().isEmpty ()) {
82+ io .println ("The '" + courseName + "' course doesn't have any exercises." );
83+ } else {
84+ io .println ("The '" + courseName + "' course has " +
85+ course .getExercises ().size () + " exercises" );
86+
87+ int failedCount = (filtered .size () - exercises .size ());
88+ if (failedCount > 0 ) {
89+ io .println (" from which " +
90+ exercises .size () + " exercises were succesfully downloaded" );
91+ io .println (Color .colorString (" and of which " + failedCount + " failed." ,
92+ Color .AnsiColor .ANSI_RED ));
93+ //TODO we could print the names of the not downloaded exercises here
94+ } else {
95+ io .println (" from which " +
96+ exercises .size () + " exercises were downloaded." );
97+ }
98+ io .println ("Use -a flag to download also your completed exercises." );
8099 }
81100
82101 Path configFile = app .getWorkDir ().getWorkingDirectory ()
83- .resolve (stringArgs [ 0 ] )
102+ .resolve (courseName )
84103 .resolve (CourseInfoIo .COURSE_CONFIG );
85104 CourseInfo info = app .createCourseInfo (course );
86105 info .setExercises (course .getExercises ());
87106 CourseInfoIo .save (info , configFile );
88107 }
89108
90- protected List <Exercise > getFilteredExercises (Course course , CommandLine args ) {
91- if (args . hasOption ( "a" ) ) {
109+ private List <Exercise > getFilteredExercises (Course course ) {
110+ if (showAll ) {
92111 return course .getExercises ();
93112 }
94113
0 commit comments