commit a23c8139cf1ef9d4141701edc0385ab26b07cebd
parent 31ec9d8f40fb2be1730ea600e5e73e2cebb8630a
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Thu, 6 Jun 2024 04:19:13 +0200
Ignore options after --
Diffstat:
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/args.hpp b/args.hpp
@@ -26,13 +26,14 @@ class Parser {
for (int i = 0; argp->options[i].key; i++) {
const auto &option = argp->options[i];
const uint8_t idx = option.key - 'a';
+
if (options[idx]) {
std::cerr << std::format("duplicate key {}\n", option.key);
throw new std::runtime_error("duplicate key");
}
- options[idx] = &option;
if (option.name) trie.insert(option.name, option.key);
+ options[idx] = &option;
}
}
@@ -45,6 +46,8 @@ class Parser {
continue;
}
+ if (!std::strcmp(argv[i], "--")) break;
+
if (argv[i][1] != '-') {
const char *opt = argv[i] + 1;
for (int j = 0; opt[j]; j++) {
@@ -91,6 +94,10 @@ class Parser {
}
}
+ for (i = i + 1; i < argc; i++) {
+ argp->parser(-1, argv[i], input);
+ }
+
return 0;
unknown:
diff --git a/demo.cpp b/demo.cpp
@@ -6,8 +6,8 @@
void error(const std::string &message) { std::cerr << message << std::endl; }
struct arguments_t {
- const char *output_file = 0;
- const char *input_file = 0;
+ const char *output_file = "";
+ const char *input_file = "";
bool debug = 0;
bool hex = 0;