prompt list, accept ranges
This commit is contained in:
+27
-4
@@ -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}.")
|
||||
continue
|
||||
|
||||
try:
|
||||
values = [int(x) for x in raw.split()]
|
||||
except ValueError:
|
||||
print("Please enter only numbers separated by spaces.")
|
||||
values = []
|
||||
ok = True
|
||||
|
||||
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
|
||||
|
||||
if any(v < min_value or v > max_value for v in values):
|
||||
|
||||
Reference in New Issue
Block a user