Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add short args to CLI #337

Closed
mpkocher opened this issue Jul 9, 2024 · 1 comment · Fixed by #339
Closed

Feature Request: Add short args to CLI #337

mpkocher opened this issue Jul 9, 2024 · 1 comment · Fixed by #339
Assignees

Comments

@mpkocher
Copy link

mpkocher commented Jul 9, 2024

"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)
@kschwab
Copy link
Contributor

kschwab commented Jul 9, 2024

Thanks @mpkocher, that's a great suggestion to use single string aliases implicitly as short flags... I'll take a peek when I get a chance, but that should be pretty straightforward to add.

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

Successfully merging a pull request may close this issue.

3 participants