prompt list, accept ranges

This commit is contained in:
2026-05-07 11:36:39 +02:00
parent 60827a4c67
commit bd169b5aa4
+27 -4
View File
@@ -37,10 +37,33 @@ def prompt_list(prompt: str, item_name: str, min_value: int, max_value: int):
print(f"Please enter at least one {item_name}.") print(f"Please enter at least one {item_name}.")
continue continue
try: values = []
values = [int(x) for x in raw.split()] ok = True
except ValueError:
print("Please enter only numbers separated by spaces.") for token in raw.split():
if "-" in token:
parts = token.split("-", 1)
if len(parts) != 2 or not parts[0].isdigit() or not parts[1].isdigit():
ok = False
break
start = int(parts[0])
end = int(parts[1])
if start > end:
print(f"Invalid range '{token}': start must be <= end.")
ok = False
break
values.extend(range(start, end + 1))
else:
if not token.isdigit():
ok = False
break
values.append(int(token))
if not ok:
print("Please enter only numbers and ranges (like 3-7), separated by spaces.")
continue continue
if any(v < min_value or v > max_value for v in values): if any(v < min_value or v > max_value for v in values):