|
| 1 | +import abc |
1 | 2 | import enum
|
2 |
| -from typing import List, Optional, Callable, Any |
| 3 | +from collections import UserDict |
| 4 | +from typing import Any, Callable, List, Optional |
3 | 5 |
|
4 |
| -from pydantic import BaseModel |
5 | 6 | import click
|
6 |
| -import abc |
7 |
| -from collections import UserDict |
8 | 7 | from prompt_toolkit.shortcuts import checkboxlist_dialog, radiolist_dialog
|
| 8 | +from pydantic import BaseModel |
9 | 9 |
|
10 | 10 | try:
|
11 | 11 | from simple_term_menu import TerminalMenu
|
|
15 | 15 |
|
16 | 16 | class Database(BaseModel):
|
17 | 17 | name: str
|
18 |
| - image: Optional[str] |
19 |
| - driver: Optional[str] |
20 |
| - async_driver: Optional[str] |
21 |
| - port: Optional[int] |
22 |
| - driver_short: Optional[str] |
| 18 | + image: Optional[str] = None |
| 19 | + driver: Optional[str] = None |
| 20 | + async_driver: Optional[str] = None |
| 21 | + port: Optional[int] = None |
| 22 | + driver_short: Optional[str] = None |
23 | 23 |
|
24 | 24 |
|
25 | 25 | class MenuEntry(BaseModel):
|
26 | 26 | code: str
|
27 |
| - cli_name: Optional[str] |
| 27 | + cli_name: Optional[str] = None |
28 | 28 | user_view: str
|
29 | 29 | description: str
|
30 |
| - is_hidden: Optional[Callable[["BuilderContext"], bool]] |
31 |
| - additional_info: Any |
| 30 | + is_hidden: Optional[Callable[["BuilderContext"], bool]] = None |
| 31 | + additional_info: Any = None |
| 32 | + pydantic_v1: bool = False |
32 | 33 |
|
33 | 34 | @property
|
34 | 35 | def generated_name(self) -> str:
|
@@ -83,13 +84,13 @@ def after_ask(self, context: "BuilderContext") -> "BuilderContext":
|
83 | 84 |
|
84 | 85 | class SingularMenuModel(BaseMenuModel):
|
85 | 86 | code: str
|
86 |
| - cli_name: Optional[str] |
| 87 | + cli_name: Optional[str] = None |
87 | 88 | description: str
|
88 |
| - before_ask_fun: Optional[Callable[["BuilderContext"], Optional[MenuEntry]]] |
| 89 | + before_ask_fun: Optional[Callable[["BuilderContext"], Optional[MenuEntry]]] = None |
89 | 90 | after_ask_fun: Optional[
|
90 | 91 | Callable[["BuilderContext", "SingularMenuModel"], "BuilderContext"]
|
91 |
| - ] |
92 |
| - parser: Optional[Callable[[str], Any]] |
| 92 | + ] = None |
| 93 | + parser: Optional[Callable[[str], Any]] = None |
93 | 94 |
|
94 | 95 | def get_cli_options(self) -> List[click.Option]:
|
95 | 96 | cli_name = self.code
|
@@ -158,6 +159,8 @@ def ask(self, context: "BuilderContext") -> Optional["BuilderContext"]:
|
158 | 159 | return
|
159 | 160 |
|
160 | 161 | setattr(context, self.code, chosen_entry.code)
|
| 162 | + if chosen_entry.pydantic_v1: |
| 163 | + context.pydanticv1 = True |
161 | 164 |
|
162 | 165 | return context
|
163 | 166 |
|
@@ -236,6 +239,10 @@ def ask(self, context: "BuilderContext") -> Optional["BuilderContext"]:
|
236 | 239 |
|
237 | 240 | for entry in chosen_entries:
|
238 | 241 | setattr(context, entry.code, True)
|
| 242 | + |
| 243 | + for ch_entry in chosen_entries: |
| 244 | + if ch_entry.pydantic_v1: |
| 245 | + context.pydanticv1 = True |
239 | 246 |
|
240 | 247 | return context
|
241 | 248 |
|
|
0 commit comments