From 2c4bafc57f278fbd2a564c357da410173be28bc6 Mon Sep 17 00:00:00 2001 From: Lily Foster Date: Wed, 25 Jan 2023 11:48:18 -0500 Subject: [PATCH] Fix option parsing without --debug after #261 From getopt manual page: > By default, getopt() permutes the contents of argv as it scans, so that eventually all the nonoptions are at the end. Two other scanning modes are also implemented. [...] If the first character of optstring is '-', then each nonoption argv-element is handled as if it were the argument of an option with character code 1. > If the first character (following any optional '+' or '-' described above) of optstring is a colon (':'), then getopt() likewise does not print an error message. In addition, it returns ':' instead of '?' to indicate a missing option argument. This allows the caller to distinguish the two different types of errors. --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 1ff7919..d18a48b 100644 --- a/main.c +++ b/main.c @@ -1148,7 +1148,7 @@ void log_init(int argc, char **argv) { optind = 1; while (1) { int opt_idx = 0; - c = getopt_long(argc, argv, "d", long_options, &opt_idx); + c = getopt_long(argc, argv, "-:d", long_options, &opt_idx); if (c == -1) { break; }