Merge pull request #783 from kiwix/fix-kiwix-mange-docopt-integration

Fix kiwix-manage docopt integration
pull/788/head
Kelson 6 months ago committed by GitHub
commit 9b91ff1529
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -60,8 +60,8 @@ static const char USAGE[] =
R"(Manipulates the Kiwix library XML file
Usage:
kiwix-manage LIBRARYPATH add [--zimPathToSave=<custom_zim_path>] [--url=<http_zim_url>] ZIMPATH
kiwix-manage LIBRARYPATH remove|delete ZIMID ...
kiwix-manage LIBRARYPATH add [--zimPathToSave=<custom_zim_path>] [--url=<http_zim_url>] ZIMPATH ...
kiwix-manage LIBRARYPATH (delete|remove) ZIMID ...
kiwix-manage LIBRARYPATH show [ZIMID ...]
kiwix-manage -v | --version
kiwix-manage -h | --help
@ -69,7 +69,7 @@ Usage:
Arguments:
LIBRARYPATH The XML library file path.
ZIMID ZIM file unique ID.
ZIMPATH A path to a zim to add.
ZIMPATH A path to a ZIM to add.
Options:
Custom options for "add" action:
@ -87,23 +87,24 @@ Examples:
Documentation:
Source code https://github.com/kiwix/kiwix-tools
More info https://wiki.kiwix.org/wiki/Kiwix-manage
More info https://wiki.kiwix.org/wiki/kiwix-manage
)";
int handle_show(const kiwix::Library& library, const std::string& libraryPath,
const Options& options)
{
if (options.at("ZIMID").isStringList()) {
auto bookIds = options.at("ZIMID").asStringList();
for(auto& bookId: bookIds) {
show(library, bookId);
}
} else {
if (options.at("ZIMID").asStringList().empty()) {
auto booksIds = library.getBooksIds();
for(auto& bookId: booksIds) {
show(library, bookId);
}
} else {
auto bookIds = options.at("ZIMID").asStringList();
for(auto& bookId: bookIds) {
show(library, bookId);
}
}
return(0);
}
@ -115,19 +116,21 @@ int handle_add(kiwix::LibraryPtr library, const std::string& libraryPath,
kiwix::Manager manager(library);
std::string zimPath = options.at("ZIMPATH").asString();
if (options.at("--zimPathToSave").isString()) {
zimPathToSave = options.at("--zimPathToSave").asString();
} else {
zimPathToSave = zimPath;
}
if (options.at("--url").isString()) {
url = options.at("--url").asString();
}
auto zimPaths = options.at("ZIMPATH").asStringList();
for (auto& zimPath: zimPaths) {
if (options.at("--zimPathToSave").isString()) {
zimPathToSave = options.at("--zimPathToSave").asString();
} else {
zimPathToSave = zimPath;
}
if (options.at("--url").isString()) {
url = options.at("--url").asString();
}
if (manager.addBookFromPathAndGetId(zimPath, zimPathToSave, url, false).empty()) {
std::cerr << "Cannot add zim " << zimPath << " to the library." << std::endl;
return 1;
if (manager.addBookFromPathAndGetId(zimPath, zimPathToSave, url, false).empty()) {
std::cerr << "Cannot add ZIM " << zimPath << " to the library." << std::endl;
return 1;
}
}
return 0;

Loading…
Cancel
Save