mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-22 11:22:38 -04:00
Do not allow multiple values for same option
Previously, kiwix-serve would take the last value for the same option. This was unintuitive. This change exits the program if multiple values for the same option are found.
This commit is contained in:
parent
da55468a88
commit
7526148f89
@ -229,6 +229,7 @@ int main(int argc, char** argv)
|
|||||||
{"searchLimit", required_argument, 0, 's'},
|
{"searchLimit", required_argument, 0, 's'},
|
||||||
{0, 0, 0, 0}};
|
{0, 0, 0, 0}};
|
||||||
|
|
||||||
|
std::set<int> usedOptions;
|
||||||
/* Argument parsing */
|
/* Argument parsing */
|
||||||
while (true) {
|
while (true) {
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
@ -236,6 +237,11 @@ int main(int argc, char** argv)
|
|||||||
= getopt_long(argc, argv, "hzmnbdvVla:p:f:t:r:i:c:ML:s:", long_options, &option_index);
|
= getopt_long(argc, argv, "hzmnbdvVla:p:f:t:r:i:c:ML:s:", long_options, &option_index);
|
||||||
|
|
||||||
if (c != -1) {
|
if (c != -1) {
|
||||||
|
auto insertRes = usedOptions.insert(c);
|
||||||
|
if (!insertRes.second) {
|
||||||
|
std::cerr << "Multiple values of same option are not allowed." << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'h':
|
case 'h':
|
||||||
usage();
|
usage();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user