You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
844 B
29 lines
844 B
package com.example.moviecli.command;
|
|
|
|
import com.example.moviecli.repository.MovieRepository;
|
|
import com.example.moviecli.view.ConsoleView;
|
|
import com.example.moviecli.model.Movie;
|
|
public class ListCommand implements Command {
|
|
private final ConsoleView view;
|
|
|
|
public ListCommand(ConsoleView view) {
|
|
this.view = view;
|
|
}
|
|
|
|
@Override
|
|
public String getName() {
|
|
return "list";
|
|
}
|
|
|
|
@Override
|
|
public void execute(String[] args, MovieRepository repository) {
|
|
var movies = repository.getAll();
|
|
if (movies.isEmpty()) {
|
|
view.printInfo("暂无数据,请先执行 crawl <url>。");
|
|
return;
|
|
}
|
|
for (Movie m : movies) {
|
|
System.out.println(m.getRank() + ". " + m.getTitle() + " - " + m.getScore());
|
|
}
|
|
}
|
|
}
|