package fi.helsinki.cs.tmc.cli.command;

import fi.helsinki.cs.tmc.cli.Application;
import fi.helsinki.cs.tmc.cli.tmcstuff.TmcUtil;

import fi.helsinki.cs.tmc.core.TmcCore;
import fi.helsinki.cs.tmc.core.domain.Course;
import fi.helsinki.cs.tmc.core.domain.Exercise;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.concurrent.Callable;

public class ListExercisesCommand implements Command {
    private static final Logger logger = LoggerFactory.getLogger(ListExercisesCommand.class);
    private Application app;

    public ListExercisesCommand(Application app) {
        this.app = app;
    }

    @Override
    public String getDescription() {
        return "List the exercises for a specific course";
    }

    @Override
    public String getName() {
        return "list-exercises";
    }

    @Override
    public void run(String[] args) {
        List<Exercise> exercises;
        Course course;
        TmcCore core;

        if (args.length == 0) {
            return;
        }

        core = this.app.getTmcCore();
        if (core == null) {
            return;
        }
        course = TmcUtil.findCourse(core, args[0]);
        exercises = course.getExercises();

        for (Exercise exercise : exercises) {
            System.out.println(exercise.getName());
        }
    }
}

@@ -906,54 +906,19 @@
     
-List%3CExercise%3E exercises;%0A        Cours
+TmcCor
 e co
-urs
+r
 e;%0A 
@@ -924,27 +924,26 @@
         
-TmcCore cor
+String nam
 e;%0A%0A    
@@ -966,24 +966,95 @@
 gth == 0) %7B%0A
+            System.out.println(%22USAGE: tmc %22 + getName() + %22 COURSE%22);%0A
             
@@ -1180,51 +1180,350 @@
     
-course = TmcUtil.findCourse(core, args%5B0%5D);
+printExercises(core, args%5B0%5D);%0A    %7D%0A%0A    public void printExercises(TmcCore core, String name) %7B%0A        List%3CExercise%3E exercises;%0A        Course course;%0A%0A        course = TmcUtil.findCourse(core, name);%0A        if (course == null) %7B%0A            System.out.println(%22There is no course with name %22 + name + %22.%22);%0A            return;%0A        %7D
 %0A   

Add null check after the findCourse method.