-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add init command to configure deployer (#127)
- Loading branch information
1 parent
ea3a67d
commit 5ac7022
Showing
10 changed files
with
476 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from enum import Enum | ||
from inspect import isclass | ||
from typing import Type | ||
|
||
from pydantic import BaseModel | ||
from rich.prompt import Prompt | ||
|
||
|
||
def ask_user_for_model_fields(model: Type[BaseModel]) -> dict: | ||
"""Ask user for model fields and return a dictionary with the results. | ||
Args: | ||
model (Type[BaseModel]): The pydantic model to configure. | ||
Returns: | ||
dict: A dictionary of the set fields. | ||
""" | ||
set_fields = {} | ||
for field_name, field_info in model.model_fields.items(): | ||
if isclass(field_info.annotation) and issubclass(field_info.annotation, BaseModel): | ||
answer = Prompt.ask( | ||
f"Do you want to configure command {field_name}?", choices=["y", "n"], default="n" | ||
) | ||
if answer == "y": | ||
set_fields[field_name] = ask_user_for_model_fields(field_info.annotation) | ||
|
||
else: | ||
annotation = field_info.annotation | ||
default = field_info.default | ||
choices = None | ||
|
||
if isclass(annotation) and issubclass(annotation, Enum): | ||
choices = list(annotation.__members__) | ||
|
||
if isclass(annotation) and annotation == bool: | ||
choices = ["y", "n"] | ||
default = "y" if field_info.default else "n" | ||
|
||
answer = Prompt.ask(field_name, default=default, choices=choices) | ||
|
||
if isclass(annotation) and annotation == bool: | ||
answer = answer == "y" | ||
|
||
if answer != field_info.default: | ||
set_fields[field_name] = answer | ||
|
||
return set_fields |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.