From 7526148f895c47dc7b7cb6602882c1902d24636d Mon Sep 17 00:00:00 2001 From: Nikhil Tanwar <2002nikhiltanwar@gmail.com> Date: Wed, 6 Jul 2022 22:51:39 +0530 Subject: [PATCH] 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. --- src/server/kiwix-serve.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index 3b36649..8f9431b 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -229,6 +229,7 @@ int main(int argc, char** argv) {"searchLimit", required_argument, 0, 's'}, {0, 0, 0, 0}}; + std::set usedOptions; /* Argument parsing */ while (true) { 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); 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) { case 'h': usage();