+ add the option --current (and fix old bad behaviour)

This commit is contained in:
kelson42 2012-01-19 19:24:18 +00:00
parent 490b0c762a
commit cdad31f904

View File

@ -93,6 +93,7 @@ int main(int argc, char **argv) {
string indexPath; string indexPath;
kiwix::supportedIndexType indexBackend = kiwix::XAPIAN; kiwix::supportedIndexType indexBackend = kiwix::XAPIAN;
string url; string url;
bool setCurrent = false;
if (argc>3) { if (argc>3) {
zimPath = argv[3]; zimPath = argv[3];
@ -107,10 +108,11 @@ int main(int argc, char **argv) {
{"indexPath", required_argument, 0, 'i'}, {"indexPath", required_argument, 0, 'i'},
{"indexBackend", required_argument, 0, 'b'}, {"indexBackend", required_argument, 0, 'b'},
{"zimPathToSave", required_argument, 0, 'z'}, {"zimPathToSave", required_argument, 0, 'z'},
{"current", no_argument, 0, 'c'},
{0, 0, 0, 0} {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) { if (c != -1) {
@ -119,6 +121,10 @@ int main(int argc, char **argv) {
url = optarg; url = optarg;
break; break;
case 'c':
setCurrent = true;
break;
case 'i': case 'i':
indexPath = optarg; indexPath = optarg;
break; break;
@ -148,16 +154,14 @@ int main(int argc, char **argv) {
string bookId = libraryManager.addBookFromPathAndGetId(zimPath, zimPathToSave, url, true); string bookId = libraryManager.addBookFromPathAndGetId(zimPath, zimPathToSave, url, true);
if (!bookId.empty()) { if (!bookId.empty()) {
if (setCurrent)
libraryManager.setCurrentBookId(bookId); libraryManager.setCurrentBookId(bookId);
/* In case of the library already had the same book and a /* Save the index infos if necessary */
corresponding path, the merge politic could should to save
the "old" one if zimPathToSave is empty */
if (zimPathToSave.empty())
libraryManager.setBookPath(bookId, zimPathToSave);
if (!indexPath.empty()) if (!indexPath.empty())
libraryManager.setBookIndex(bookId, indexPath, indexBackend); libraryManager.setBookIndex(bookId, indexPath, indexBackend);
} else { } else {
cerr << "Unable to build or save library file '" << libraryPath << "'" << endl; cerr << "Unable to build or save library file '" << libraryPath << "'" << endl;
} }