New --version argument to kiwix-manage

This commit is contained in:
Kelson 2019-08-25 18:15:16 +02:00
parent d17fd2af94
commit 4eb38869c1

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2011 Emmanuel Engelhart <kelson@kiwix.org> * Copyright 2011-2019 Emmanuel Engelhart <kelson@kiwix.org>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -23,6 +23,8 @@
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include "../version.h"
using namespace std; using namespace std;
enum supportedAction { NONE, ADD, SHOW, REMOVE }; 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--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 << "\t\t\t--url=HTTP_ZIM_URL to create an \"url\" attribute for the online version of the ZIM file" << std::endl
<< 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 << "Examples:" << std::endl
<< "\tAdd ZIM files to library: kiwix-manage my_library.xml add first.zim second.zim" << 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': case 'u':
url = optarg; url = optarg;
break; break;
case 'o': case 'o':
origID = optarg; origID = optarg;
break; break;
case 'z': case 'z':
zimPathToSave = optarg; zimPathToSave = optarg;
break; break;
@ -217,7 +220,27 @@ int main(int argc, char** argv)
supportedAction action = NONE; supportedAction action = NONE;
kiwix::Library library; 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) { if (argc > 2) {
libraryPath = argv[1]; libraryPath = argv[1];
string actionString = argv[2]; string actionString = argv[2];