From 4eb38869c1074a8d61422f1b1777c32aa37dd755 Mon Sep 17 00:00:00 2001 From: Kelson Date: Sun, 25 Aug 2019 18:15:16 +0200 Subject: [PATCH] New --version argument to kiwix-manage --- src/manager/kiwix-manage.cpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/manager/kiwix-manage.cpp b/src/manager/kiwix-manage.cpp index e676151..5b0334b 100644 --- a/src/manager/kiwix-manage.cpp +++ b/src/manager/kiwix-manage.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011 Emmanuel Engelhart + * Copyright 2011-2019 Emmanuel Engelhart * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,8 @@ #include #include +#include "../version.h" + using namespace std; enum supportedAction { NONE, ADD, SHOW, REMOVE }; @@ -78,6 +80,9 @@ void usage() << "\t\t\t--zimPathToSave=CUSTOM_ZIM_PATH to replace the current ZIM file path" << std::endl << "\t\t\t--url=HTTP_ZIM_URL to create an \"url\" attribute for the online version of the ZIM file" << std::endl << std::endl + << "\t\t\tOther options:" << std::endl + << "\t\t\t-v, --version to print the software version" << std::endl + << std::endl << "Examples:" << std::endl << "\tAdd ZIM files to library: kiwix-manage my_library.xml add first.zim second.zim" << std::endl @@ -144,11 +149,9 @@ int handle_add(kiwix::Library* library, const std::string& libraryPath, case 'u': url = optarg; break; - case 'o': origID = optarg; break; - case 'z': zimPathToSave = optarg; break; @@ -217,7 +220,27 @@ int main(int argc, char** argv) supportedAction action = NONE; kiwix::Library library; - /* Argument parsing */ + /* General argument parsing */ + static struct option long_options[] = { + {"version", no_argument, 0, 'v'}, + {0, 0, 0, 0} + }; + + int option_index = 0; + int c; + while (true) { + c = getopt_long(argc, argv, "v", long_options, &option_index); + if (c == -1) + break; + + switch (c) { + case 'v': + version(); + return 0; + } + } + + /* Action related argument parsing */ if (argc > 2) { libraryPath = argv[1]; string actionString = argv[2];