Fix handling of --help and --version

This commit is contained in:
Kovid Goyal
2025-04-27 15:25:51 +05:30
parent 9961bdf6b5
commit 1413d8fb85
4 changed files with 38 additions and 13 deletions

View File

@@ -252,6 +252,13 @@ def c_str(x: str) -> str:
def generate_c_parser_for(funcname: str, spec: str) -> Iterator[str]:
names_map, _, defaults_map = get_option_maps(parse_option_spec(spec)[0])
if 'help' not in names_map:
names_map['help'] = {'type': 'bool-set', 'aliases': ('--help', '-h')} # type: ignore
defaults_map['help'] = False
if 'version' not in names_map:
names_map['version'] = {'type': 'bool-set', 'aliases': ('--version', '-v')} # type: ignore
defaults_map['version'] = False
yield f'static void\nparse_cli_for_{funcname}(CLISpec *spec, int argc, char **argv) {{' # }}
yield '\tFlagSpec flag;'
for name, opt in names_map.items():