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.

36 lines
947 B

package com.cctv.news.command;
import com.cctv.news.view.OutputView;
import java.util.List;
public class ListCommand implements Command {
private final OutputView view;
private final List<String> articles;
public ListCommand(OutputView view, List<String> articles) {
this.view = view;
this.articles = articles;
}
@Override
public String getName() {
return "list";
}
@Override
public String getHelp() {
return "list - 显示已抓取的文章列表";
}
@Override
public void execute(String[] args) {
if (articles.isEmpty()) {
view.showMessage("目前没有已抓取的文章,请先使用 crawl 命令。");
} else {
view.showMessage("已抓取的文章列表:");
for (int i = 0; i < articles.size(); i++) {
view.showArticles((i + 1) + ". " + articles.get(i));
}
}
}
}