Skip to content

[QUESTION] How to automatically validate input parameter as IPv4Address #239

Description

@johnthagen

First check

  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the Typer documentation, with the integrated search.
  • I already searched in Google "How to X in Typer" and didn't find any information.
  • I already searched in Google "How to X in Click" and didn't find any information.

Description

With argparse it it possible to do something like:

    parser.add_argument(
        "--host",
        type=IPv4Address,
        default=IPv4Address("127.0.0.1"),
    )

This will automatically try to construct a IPv4Address type from the input and validate that it is a valid IPv4Address.

$ main.py --host=a
...
main.py: error: argument --host: invalid IPv4Address value: 'a'

I didn't see this type documented in typer. Is this possible to do?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions