1 changed files with 0 additions and 33 deletions
@ -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…
Reference in new issue