Browse Source

删除 'project/java-cli/src/main/java/com/example/datacollect/command/SaveCommand.java'

main
LeiJuntao 3 weeks ago
parent
commit
14062a2489
  1. 33
      project/java-cli/src/main/java/com/example/datacollect/command/SaveCommand.java

33
project/java-cli/src/main/java/com/example/datacollect/command/SaveCommand.java

@ -1,33 +0,0 @@
package com.example.datacollect.command;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.example.datacollect.repository.ArticleRepository;
import com.example.datacollect.view.ConsoleView;
public class SaveCommand implements Command {
private static final Logger logger = LoggerFactory.getLogger(SaveCommand.class);
private final ConsoleView view;
public SaveCommand(ConsoleView view) {
this.view = view;
}
@Override
public String getName() {
return "save";
}
@Override
public void execute(String[] args, ArticleRepository repository) {
String filePath = args.length > 1 ? args[1] : "articles.txt";
try {
repository.saveToFile(filePath);
view.printSuccess("Saved " + repository.size() + " articles to " + filePath);
} catch (Exception e) {
view.printError("Failed to save: " + e.getMessage());
logger.error("Failed to save articles to file", e);
}
}
}
Loading…
Cancel
Save