Closed Geo5 closed 1 month ago
@kschwab Please take a look when you have time.
@Geo5, I presume just like argparse
this should be applied on a per field setting? e.g.:
class Settings(BaseSettings):
field: CliSuppress[int] = Field(description='Hide this field from help')
This is not hard to add, I can put up a PR if the above looks reasonable. Obviously, "field" still gets parsed at the CLI and is only hidden from CLI --help text.
Yes exactly, it is only hidden from CLI --help, but still gets parsed.
Do i understand the library correctly, that if this would be added via a type parameter (e.g. CliSuppress
) it would not be possible to set this dynamically at runtime?
The use case is, that i sometime want to show/hide some options depending on the environment (windows/linux, installed somewhere or not, etc), which with arparse would be something like:
parser.add_argument("--foo", help=argparse.SUPPRESS if platform=="linux" else "This is the foo argument")
That's a great point. I added support for both in #436. e.g.:
class Settings(BaseSettings, use_attribute_docstrings=True):
field: CliSuppress[int]
"""Hide this field from help"""
foo: int = Field(description=CLI_SUPPRESS if platform=="linux" else "This is the foo argument")
Looks great, thank you!
In stdlib argparse you are able to set the help message to
argparse.SUPPRESS
to hide the entry from the generated--help
output.Would it be possible to support this in pydantic-settings as well? It seems to work, if you add a
here https://github.com/pydantic/pydantic-settings/blob/main/pydantic_settings/sources.py#L1885 and setting the field description to
argparse.SUPPRESS