Skip to content

Commit e784085

Browse files
committed
Replaced parts of 'add_create_directories' with the generic dict constructor
1 parent a8e66eb commit e784085

File tree

1 file changed

+14
-31
lines changed

1 file changed

+14
-31
lines changed

src/murfey/cli/generate_config.py

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,11 @@ def construct_dict(
180180
dict_name: str,
181181
key_name: str,
182182
value_name: str,
183-
allow_empty_key: bool = True,
184183
key_method: Optional[Callable] = None,
185184
key_method_args: dict = {},
186185
value_method: Optional[Callable] = None,
187186
value_method_args: dict = {},
187+
allow_empty_key: bool = True,
188188
allow_empty_value: bool = True,
189189
allow_eval: bool = True,
190190
sort_keys: bool = True,
@@ -425,14 +425,7 @@ def ask_about_xml_path() -> bool:
425425
"Does this software package have a settings file that needs modification? "
426426
"(y/n)"
427427
)
428-
while True:
429-
answer = prompt(message, style="yellow").lower().strip()
430-
# Validate
431-
if answer in ("y", "yes"):
432-
return True
433-
if answer in ("n", "no"):
434-
return False
435-
console.print("Invalid input.", style="red")
428+
return ask_for_permission(message)
436429

437430
def get_xml_file() -> Optional[Path]:
438431
message = (
@@ -673,29 +666,19 @@ def get_folder_alias() -> str:
673666
Start of add_create_directories
674667
"""
675668
print_field_info(field)
676-
folders_to_create: dict[str, str] = {}
677669
category = "folder for Murfey to create"
678-
add_directory: bool = ask_for_input(category, False)
679-
while add_directory is True:
680-
folder_name = get_folder()
681-
if not folder_name:
682-
console.print(
683-
"No folder name provided",
684-
style="red",
685-
)
686-
add_directory = ask_for_input(category, True)
687-
continue
688-
folder_alias = get_folder_alias()
689-
if not folder_alias:
690-
console.print(
691-
"No folder alias provided",
692-
style="red",
693-
)
694-
add_directory = ask_for_input(category, True)
695-
continue
696-
folders_to_create[folder_alias] = folder_name
697-
add_directory = ask_for_input(category, True)
698-
continue
670+
folders_to_create: dict[str, str] = construct_dict(
671+
dict_name=category,
672+
key_name="folder alias",
673+
value_name="folder name",
674+
key_method=get_folder_alias,
675+
value_method=get_folder,
676+
allow_empty_key=False,
677+
allow_empty_value=False,
678+
allow_eval=False,
679+
sort_keys=True,
680+
restrict_to_types=str,
681+
)
699682

700683
# Validate and return
701684
try:

0 commit comments

Comments
 (0)