mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-22 11:22:38 -04:00
+ add the option --current (and fix old bad behaviour)
This commit is contained in:
parent
490b0c762a
commit
cdad31f904
@ -93,6 +93,7 @@ int main(int argc, char **argv) {
|
||||
string indexPath;
|
||||
kiwix::supportedIndexType indexBackend = kiwix::XAPIAN;
|
||||
string url;
|
||||
bool setCurrent = false;
|
||||
|
||||
if (argc>3) {
|
||||
zimPath = argv[3];
|
||||
@ -107,10 +108,11 @@ int main(int argc, char **argv) {
|
||||
{"indexPath", required_argument, 0, 'i'},
|
||||
{"indexBackend", required_argument, 0, 'b'},
|
||||
{"zimPathToSave", required_argument, 0, 'z'},
|
||||
{"current", no_argument, 0, 'c'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
c = getopt_long(argc, argv, "z:u:i:b:", long_options, &option_index);
|
||||
c = getopt_long(argc, argv, "cz:u:i:b:", long_options, &option_index);
|
||||
|
||||
if (c != -1) {
|
||||
|
||||
@ -119,6 +121,10 @@ int main(int argc, char **argv) {
|
||||
url = optarg;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
setCurrent = true;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
indexPath = optarg;
|
||||
break;
|
||||
@ -148,16 +154,14 @@ int main(int argc, char **argv) {
|
||||
string bookId = libraryManager.addBookFromPathAndGetId(zimPath, zimPathToSave, url, true);
|
||||
|
||||
if (!bookId.empty()) {
|
||||
|
||||
if (setCurrent)
|
||||
libraryManager.setCurrentBookId(bookId);
|
||||
|
||||
/* In case of the library already had the same book and a
|
||||
corresponding path, the merge politic could should to save
|
||||
the "old" one if zimPathToSave is empty */
|
||||
if (zimPathToSave.empty())
|
||||
libraryManager.setBookPath(bookId, zimPathToSave);
|
||||
|
||||
/* Save the index infos if necessary */
|
||||
if (!indexPath.empty())
|
||||
libraryManager.setBookIndex(bookId, indexPath, indexBackend);
|
||||
|
||||
} else {
|
||||
cerr << "Unable to build or save library file '" << libraryPath << "'" << endl;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user