def get_options(options, choice_name):
import questionary
args = {o:v for o,v in options.values()}
bools = [k for k,v in [(k,v[1]) for k,v in options.items()] if isinstance(v, bool)]
strings = [k for k,v in [(k,v[1]) for k,v in options.items()] if isinstance(v, str)]
toggles = { o:(f"[ ] {o}", f"[x] {o}") for o in bools }
def update_string(args, choice):
opt = options[choice][0]
args[opt] = questionary.text(f"{choice} (current: {args[opt]}): ").ask()
return args
def update_bool(args, choice):
opt = options[choice][0]
args[opt] = not args[opt]
return args
exits = {
"[Run Test]": lambda args: args,
"[Back]": lambda args: None,
"[Quit]": lambda args: False
}
while True:
toggle_labels = { toggles[o][1] if args[options[o][0]] else toggles[o][0] : o for o in bools }
string_labels = { f"{o}: ({args[options[o][0]]})" : o for o in strings }
all_labels = {**toggle_labels, **string_labels}
updates = {**{choice:update_bool for choice in toggle_labels.values()},
**{choice:update_string for choice in string_labels.values()}}
choice = questionary.select(
f"Additional Options for Test: {choice_name}",
choices=[
*all_labels,
questionary.Separator(),
*exits
]
).ask()
if choice in exits:
return exits[choice](args)
choice = all_labels.get(choice, None)
print(choice)
args = updates.get(choice, lambda args, choice: args)(args, choice)