From 34ceaf37f28ef03764904bb426d520530ad8115d Mon Sep 17 00:00:00 2001 From: Emmanuel Engelhart Date: Thu, 18 Apr 2019 20:31:22 +0200 Subject: [PATCH 1/2] Better kiwix-serve usage() --- Changelog | 1 + src/server/kiwix-serve.cpp | 53 +++++++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/Changelog b/Changelog index 0b3d931..90b026f 100644 --- a/Changelog +++ b/Changelog @@ -9,6 +9,7 @@ kiwix-manage kiwix-serve ----------- + * Better usage() * Display properly welcome page on 3 columns kiwix-tools 1.2.1 diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index 9cbab35..9244726 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -105,6 +105,7 @@ static kiwix::Library library; static pthread_mutex_t searchLock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t compressorLock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t regexLock = PTHREAD_MUTEX_INITIALIZER; +static unsigned int nb_threads = 4; std::pair get_from_humanReadableBookId(const std::string& humanReadableBookId) { @@ -936,6 +937,42 @@ bool hasHumanReadableIdCollision(const string &humanReadableId, return false; } +void usage() +{ + std::cout << "Usage:" << std::endl + << "\tkiwix-serve [OPTIONS] ZIM_PATH+" << std::endl + << "\tkiwix-serve --library [OPTIONS] LIBRARY_PATH" << std::endl + << std::endl + + << "Purpose:" << std::endl + << "\tDeliver ZIM file articles via HTTP" + << std::endl << std::endl + + << "Mandatory arguments:" << std::endl + << "\tLIBRARY_PATH\t\tis the XML library file path listing ZIM file to serve. To be used only with the --library argument." + << std::endl + << "\tZIM_PATH\t\tis the path of a ZIM file." + << std::endl << std::endl + + << "Optional arguments:" << std::endl + << "\t-a, --attachToProcess\texit if given process id is not running anymore" << std::endl + << "\t-d, --daemon\t\tdetach the HTTP server daemon from the main process" << std::endl + << "\t-f, --interface\t\tlisten only on this interface, all available ones otherwise (POSIX only)" << std::endl + << "\t-m, --nolibrarybutton\tdo not print the builtin home button in the builtin top bar overlay" << std::endl + << "\t-n, --nosearchbar\tdo not print the builtin bar overlay on the top of each served page" << std::endl + << "\t-p, --port\t\tTCP port on which to listen to HTTP requests (default: 80)" << std::endl + << "\t-r, --urlRootLocation\tURL prefix on which the content should be made available (default: /)" << std::endl + << "\t-t, --threads\t\tnumber of threads to run in parallel (default: " << nb_threads << ")" << std::endl + << "\t-v, --verbose\t\tprint debug log to STDOUT" << std::endl + << "\t-z, --nodatealiases\tcreate URL aliases for each content by removing the date" << std::endl + << std::endl + + << "Documentation:" << std::endl + << "\tSource code\t\thttps://github.com/kiwix/kiwix-tools" << std::endl + << "\tMore info\t\thttps://wiki.kiwix.org/wiki/Kiwix-serve" << std::endl + << std::endl; +} + int main(int argc, char** argv) { struct MHD_Daemon* daemon; @@ -948,7 +985,6 @@ int main(int argc, char** argv) int libraryFlag = false; string PPIDString; unsigned int PPID = 0; - unsigned int nb_threads = 4; static struct option long_options[] = {{"daemon", no_argument, 0, 'd'}, @@ -1033,20 +1069,7 @@ int main(int argc, char** argv) /* Print usage)) if necessary */ if (zimPathes.empty() && libraryPath.empty()) { - cerr << "Usage: kiwix-serve [--index=INDEX_PATH] [--port=PORT] [--verbose] " - "[--nosearchbar] [--nolibrarybutton] [--nodatealiases] [--daemon] " - "[--attachToProcess=PID] [--interface=IF_NAME] " - "[--urlRootLocation=/URL_ROOT] " - "[--threads=NB_THREAD(" << nb_threads << ")] ZIM_PATH+" - << endl; - cerr << " kiwix-serve --library [--port=PORT] [--verbose] [--daemon] " - "[--nosearchbar] [--nolibrarybutton] [--nodatealiases] [--attachToProcess=PID] " - "[--interface=IF_NAME] [--urlRootLocation=/URL_ROOT] " - "[--threads=NB_THREAD(" << nb_threads << ")] LIBRARY_PATH " - << endl; - cerr << "\n If you set more than one ZIM_PATH, you cannot set a " - "INDEX_PATH." - << endl; + usage(); exit(1); } From c6499ad5c60086faf3540bc98b2f1e0729de03ec Mon Sep 17 00:00:00 2001 From: Kelson Date: Fri, 3 May 2019 11:41:18 +0200 Subject: [PATCH 2/2] Fix typo in kiwix-manage usage() --- src/manager/kiwix-manage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/manager/kiwix-manage.cpp b/src/manager/kiwix-manage.cpp index 8080d2b..89ced54 100644 --- a/src/manager/kiwix-manage.cpp +++ b/src/manager/kiwix-manage.cpp @@ -84,7 +84,7 @@ void usage() << "Examples:" << std::endl << "\tAdd ZIM files to library: kiwix-manage my_library.xml add first.zim second.zim" << std::endl - << "\tRemove ZIM fiels from library: kiwix-manage my_library.xml remove e5c2c003-b49e-2756-5176-5d9c86393dd9" << std::endl + << "\tRemove ZIM files from library: kiwix-manage my_library.xml remove e5c2c003-b49e-2756-5176-5d9c86393dd9" << std::endl << "\tShow all library ZIM files: kiwix-manage my_library.xml show" << std::endl << std::endl