diff --git a/duckargs/__init__.py b/duckargs/__init__.py index 9526dd5..f665a36 100644 --- a/duckargs/__init__.py +++ b/duckargs/__init__.py @@ -462,7 +462,11 @@ def _generate_c_getopt_code(processed_args, getopt_string, opts, positionals, ha desc = f"Positional argument #{i + 1} ({arg.var_name})" optarg = f"argv[optind]" ret += '\n'.join([" " + x for x in _generate_c_opt_lines(arg, desc, optarg)]) - ret += "\n optind++;\n\n" + + if i < (len(positionals) - 1): + ret += "\n optind++;" + + ret += "\n\n" pass diff --git a/tests/test_data/choices/expected_c.txt b/tests/test_data/choices/expected_c.txt index 6f2a573..122255b 100644 --- a/tests/test_data/choices/expected_c.txt +++ b/tests/test_data/choices/expected_c.txt @@ -80,7 +80,6 @@ int parse_args(int argc, char *argv[]) optind++; pos2 = argv[optind]; - optind++; return 0; } diff --git a/tests/test_data/env_all/expected_c.txt b/tests/test_data/env_all/expected_c.txt index 976b877..8e980a1 100644 --- a/tests/test_data/env_all/expected_c.txt +++ b/tests/test_data/env_all/expected_c.txt @@ -104,7 +104,6 @@ int parse_args(int argc, char *argv[]) optind++; positional_arg2 = argv[optind]; - optind++; return 0; } diff --git a/tests/test_data/env_comment/expected_c.txt b/tests/test_data/env_comment/expected_c.txt index bfc6661..f0609c0 100644 --- a/tests/test_data/env_comment/expected_c.txt +++ b/tests/test_data/env_comment/expected_c.txt @@ -104,7 +104,6 @@ int parse_args(int argc, char *argv[]) optind++; positional_arg2 = argv[optind]; - optind++; return 0; } diff --git a/tests/test_data/env_print/expected_c.txt b/tests/test_data/env_print/expected_c.txt index cc17c2b..d6dcb75 100644 --- a/tests/test_data/env_print/expected_c.txt +++ b/tests/test_data/env_print/expected_c.txt @@ -107,7 +107,6 @@ int parse_args(int argc, char *argv[]) optind++; positional_arg2 = argv[optind]; - optind++; return 0; } diff --git a/tests/test_data/many_opts/expected_c.txt b/tests/test_data/many_opts/expected_c.txt index a2b4339..008eb61 100644 --- a/tests/test_data/many_opts/expected_c.txt +++ b/tests/test_data/many_opts/expected_c.txt @@ -208,7 +208,6 @@ int parse_args(int argc, char *argv[]) optind++; pos10 = argv[optind]; - optind++; return 0; } diff --git a/tests/test_data/negative_hex/expected_c.txt b/tests/test_data/negative_hex/expected_c.txt index df7e8c1..db61809 100644 --- a/tests/test_data/negative_hex/expected_c.txt +++ b/tests/test_data/negative_hex/expected_c.txt @@ -70,7 +70,6 @@ int parse_args(int argc, char *argv[]) printf("Positional argument #1 (positional_arg0) requires an integer argument\n"); return -1; } - optind++; return 0; } diff --git a/tests/test_data/negative_int/expected_c.txt b/tests/test_data/negative_int/expected_c.txt index 5055b6b..f1a37a1 100644 --- a/tests/test_data/negative_int/expected_c.txt +++ b/tests/test_data/negative_int/expected_c.txt @@ -80,7 +80,6 @@ int parse_args(int argc, char *argv[]) printf("Positional argument #2 (positional_arg1) requires an integer argument\n"); return -1; } - optind++; return 0; } diff --git a/tests/test_data/normalize_names/expected_c.txt b/tests/test_data/normalize_names/expected_c.txt index 81f8217..637d903 100644 --- a/tests/test_data/normalize_names/expected_c.txt +++ b/tests/test_data/normalize_names/expected_c.txt @@ -87,7 +87,6 @@ int parse_args(int argc, char *argv[]) optind++; pos___3 = argv[optind]; - optind++; return 0; } diff --git a/tests/test_data/positional_values/expected_c.txt b/tests/test_data/positional_values/expected_c.txt index bb83ce4..0a54c83 100644 --- a/tests/test_data/positional_values/expected_c.txt +++ b/tests/test_data/positional_values/expected_c.txt @@ -70,7 +70,6 @@ int parse_args(int argc, char *argv[]) optind++; hello = argv[optind]; - optind++; return 0; } diff --git a/tests/test_data/readme_example/expected_c.txt b/tests/test_data/readme_example/expected_c.txt index bcf0e65..74f3712 100644 --- a/tests/test_data/readme_example/expected_c.txt +++ b/tests/test_data/readme_example/expected_c.txt @@ -107,7 +107,6 @@ int parse_args(int argc, char *argv[]) optind++; positional_arg2 = argv[optind]; - optind++; return 0; }