Skip to content

Commit 0cffe36

Browse files
committed
Allowed more functions to offer to be run again if a field fails validation
1 parent 2925f66 commit 0cffe36

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/murfey/cli/generate_config.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,8 @@ def add_calibrations(
462462
if debug:
463463
console.print(error, style="red")
464464
console.print(f"Failed to validate {key!r}.", style="red")
465+
if ask_for_input(category, True) is True:
466+
return add_calibrations(key, field, debug)
465467
console.print("Returning an empty dictionary", style="red")
466468
return {}
467469

@@ -485,6 +487,7 @@ def get_software_name() -> str:
485487
console.print("Invalid software name.", style="red")
486488
if ask_for_input("software package", True) is True:
487489
return get_software_name()
490+
console.print("Returning an empty string.", style="red")
488491
return ""
489492

490493
def ask_about_settings_file() -> bool:
@@ -647,8 +650,9 @@ def get_settings_tree_path() -> str:
647650
if debug:
648651
console.print(error, style="red")
649652
console.print(f"Failed to validate {field_name!r}", style="red")
650-
console.print("Please try again.", style="red")
651-
return add_software_packages(config)
653+
if ask_for_input("software package configuration", True) is True:
654+
return add_software_packages(config)
655+
console.print(f"Skipped adding {field_name!r}.", style="red")
652656

653657
# Return updated dictionary
654658
return config
@@ -682,6 +686,7 @@ def add_data_directories(
682686
console.print(f"Failed to validate {key!r}.", style="red")
683687
if ask_for_input(category, True) is True:
684688
return add_data_directories(key, field, debug)
689+
console.print("Returning an empty dictionary.", style="red")
685690
return {}
686691

687692

@@ -721,6 +726,7 @@ def add_create_directories(
721726
console.print(f"Failed to validate {key!r}.", style="red")
722727
if ask_for_input(category, True) is True:
723728
return add_create_directories(key, field, debug)
729+
console.print("Returning an empty dictionary.", style="red")
724730
return {}
725731

726732

@@ -755,6 +761,7 @@ def add_analyse_created_directories(
755761
console.print(f"Failed to validate {key!r}.", style="red")
756762
if ask_for_input(category, True) is True:
757763
return add_analyse_created_directories(key, field, debug)
764+
console.print("Returning an empty list.", style="red")
758765
return []
759766

760767

@@ -791,6 +798,7 @@ def get_upstream_data_directories(
791798
console.print(f"Failed to validate {key!r}.", style="red")
792799
if ask_for_input(category, True) is True:
793800
return get_upstream_data_directories(key, field, debug)
801+
console.print("Returning an empty list.", style="red")
794802
return []
795803

796804
def get_upstream_data_tiff_locations(
@@ -821,6 +829,7 @@ def get_upstream_data_tiff_locations(
821829
console.print(f"Failed to validate {key!r}.", style="red")
822830
if ask_for_input(category, True) is True:
823831
return get_upstream_data_tiff_locations(key, field, debug)
832+
console.print("Returning an empty list.", style="red")
824833
return []
825834

826835
"""
@@ -836,21 +845,15 @@ def get_upstream_data_tiff_locations(
836845
"upstream_data_tiff_locations",
837846
):
838847
field = MachineConfig.__fields__[key]
839-
# Use populate field to process simpler keys
840-
if key in (
841-
"data_transfer_enabled",
842-
"rsync_basepath",
843-
"rsync_module",
844-
"allow_removal",
845-
"upstream_data_download_directory",
846-
):
847-
validated_value = populate_field(key, field, debug)
848-
849848
# Construct more complicated data structures
850849
if key == "upstream_data_directories":
851-
validated_value = get_upstream_data_directories(key, field, debug)
852-
if key == "upstream_data_tiff_locations":
850+
validated_value: Any = get_upstream_data_directories(key, field, debug)
851+
elif key == "upstream_data_tiff_locations":
853852
validated_value = get_upstream_data_tiff_locations(key, field, debug)
853+
# Use populate field to process simpler keys
854+
else:
855+
validated_value = populate_field(key, field, debug)
856+
854857
# Add to config
855858
config[key] = validated_value
856859

0 commit comments

Comments
 (0)