Skip to content

Conversation

@dapimentel
Copy link

Given the following simple patch to long.c, the undesirable feature of parsing optional arguments for long options is demonstrated:

diff --git a/examples/long.c b/examples/long.c
index 00993fa..4ba63b9 100644
--- a/examples/long.c
+++ b/examples/long.c
@@ -48,7 +48,12 @@ int main(int argc, char **argv)
         }
     }
 
-    /* Print remaining arguments. */
+    printf("amend : %s\n", amend ? "true" : "false");
+    printf("brief : %s\n", brief ? "true" : "false");
+    printf("color : %s\n", color);
+    printf("delay : %d\n", delay);
+
+    printf("Print remaining arguments:\n");
     while ((arg = optparse_arg(&options)))
         printf("%s\n", arg);

First use case fails to reset the delay value.

%> long.x --delay 10 -a bob
amend : true
brief : false
color : white
delay : 1
Print remaining arguments:
10
bob

Second use case resets the delay value.

%> long.x --delay=10 -a bob
amend : true
brief : false
color : white
delay : 10
Print remaining arguments:
bob

Both use cases should behave the same as the second.

This preferred behavior is as simple as activating the included patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant