pydantic-cli icon indicating copy to clipboard operation
pydantic-cli copied to clipboard

Fix _add_pydantic_field_to_parser using cli annotation as parser args

Open calgray opened this issue 1 month ago • 1 comments

This MR performs a significant change to resolve the issue of not being able to declare CLI positional arguments by passing annotated cli arguments directly to argparse.

In doing so, this means that no CLI annotation results in argparse doing the default behaviour of creating cli positional arguments instead of keyworded. Required --name=value arguments are however still supported, they just require an explicit Field(cli="--name") annotation.

Providing only a default value (no annotation) still creates a CLI keyworded argument (same behaviour as typer) and is controlled by the line:

args = () if is_required else (f"{long_prefix}{field_id}",)

May want to consider performing the exact same behaviour to typer in this case and auto-generate a kebab-case keyword argument.

calgray avatar Dec 10 '25 08:12 calgray