From 1032a46c5760eb029f79a8c2715d74bfb539572a Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 12 Nov 2018 14:00:45 +0100 Subject: [PATCH] Be able to remove several books in a single command. Fix #236 --- src/manager/kiwix-manage.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/manager/kiwix-manage.cpp b/src/manager/kiwix-manage.cpp index b47a4e1..cb037de 100644 --- a/src/manager/kiwix-manage.cpp +++ b/src/manager/kiwix-manage.cpp @@ -165,19 +165,22 @@ bool handle_remove(kiwix::Library* library, const std::string& libraryPath, const unsigned int totalBookCount = library->getBookCount(true, true); bool exitCode = 0; - if (argc > 3) { - bookId = argv[3]; + if (argc <= 3) { + std::cerr << "BookId to remove missing in the command line" << std::endl; + return (-1); } - if (!library->removeBookById(bookId)) { - if (totalBookCount > 0) { - std::cerr - << "Invalid book id." << std::endl; - exitCode = 1; - } else { - std::cerr - << "Invalid book id. Library is empty, no book to delete." - << std::endl; + if (!totalBookCount) { + std::cerr << "Library is empty, no book to delete." + << std::endl; + return 1; + } + + for (int i = 3; iremoveBookById(bookId)) { + std::cerr << "Invalid book id '" << bookId << "'." << std::endl; exitCode = 1; } }