Compare commits

..

No commits in common. "4b4ac7f0c9950da58f711a25e0cb7ece0da43c96" and "5100e3791b267f43c4d48fa62212b51e90e5e2fa" have entirely different histories.

2 changed files with 0 additions and 36 deletions

View File

@ -46,7 +46,6 @@ public class CliEngine {
registerCommand(new CreateCommand());
registerCommand(new ListCommand());
registerCommand(new CompleteCommand());
registerCommand(new DeleteCommand());
}
void handleHelp() {

View File

@ -1,35 +0,0 @@
package ru.kamask.pet.todo.cli;
import java.util.Optional;
import ru.kamask.pet.todo.service.TaskService;
public class DeleteCommand implements Command {
@Override
public String name() {
return "delete";
}
@Override
public String usage() {
return String.format(Command.templateUsage, name() + " <ID>", "Удалить задачу.");
}
@Override
public Optional<String> handle(String[] args, TaskService service) {
if (args.length != 1)
return Optional.of(Command.errorMessage);
try {
int id = Integer.parseInt(args[0]);
if (!service.has(id))
return Optional.of("Задача ID-%d не найдена.".formatted(id));
service.remove(id);
return Optional.of("Задача ID-%d удалена.".formatted(id));
} catch (NumberFormatException e) {
return Optional.of("ID - должен быть числом.");
}
}
}