Skip to content

Feature Request: Add short args to CLI #337

Closed
@mpkocher

Description

@mpkocher

"Short" args (or aliases) are useful in commanding tools. For example --name could have an alias of -n.

Acceptance Criteria

  • Enable short args using AliasChoices that are 1 char (e.g., n should translate to -n. Currently, these translate to --n).
  • The usage:... string should contain the full name
  • Update docs to include an example

Example:

from pydantic import Field, AliasChoices
from pydantic_settings import BaseSettings


class Settings(BaseSettings, cli_parse_args=True):
    name: str = Field(validation_alias=AliasChoices('n', 'name'))
    age: int

Yields:

usage: example.py [-h] [--n str] [--age int]

options:
  -h, --help           show this help message and exit
  --n str, --name str  (required)
  --age int            (required)

It should return:

usage: example.py [-h] [--name str] [--age int]

options:
  -h, --help           show this help message and exit
  -n str, --name str  (required)
  --age int            (required)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions