Skip to content

Person

sereto.cli.person

prompt_user_for_person(person_type)

Interactively prompt for a person's details.

Parameters:

Name Type Description Default
person_type PersonType

The type of person to prompt for.

required

Returns:

Type Description
Person

The person as provided by the user.

Source code in sereto/cli/person.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
@validate_call
def prompt_user_for_person(person_type: PersonType) -> Person:
    """Interactively prompt for a person's details.

    Args:
        person_type: The type of person to prompt for.

    Returns:
        The person as provided by the user.
    """
    name = prompt("Name: ")
    business_unit = prompt("Business unit: ")
    while True:
        try:
            e = prompt("Email: ")
            ta: TypeAdapter[EmailStr] = TypeAdapter(EmailStr)  # hack for mypy
            email: EmailStr | None = ta.validate_python(e) if len(e) > 0 else None
            break
        except ValidationError:
            Console().print("[red]Please enter valid email address")
    role = prompt("Role: ")

    return Person(
        type=person_type,
        name=name if len(name) > 0 else None,
        business_unit=business_unit if len(business_unit) > 0 else None,
        email=email,
        role=role if len(role) > 0 else None,
    )