Skip to content

Commit f3344d5

Browse files
committed
switch _get_ops_object to use ask_enumerate_dict
1 parent 0f14039 commit f3344d5

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

‎paths_cli/tests/wizard/test_load_from_ops.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_get_ops_object(ops_file_fixture, with_failure):
7979
assert obj.name == 'bar'
8080
log = wizard.console.log_text
8181
assert 'name of the FOOMAGIC' in log
82-
fail_msg = 'Something went wrong'
82+
fail_msg = 'not a valid option'
8383
if with_failure:
8484
assert fail_msg in log
8585
else:

‎paths_cli/wizard/load_from_ops.py‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,14 @@ def _get_ops_storage(wizard):
3131

3232
@get_object
3333
def _get_ops_object(wizard, storage, store_name, obj_name):
34-
name = wizard.ask(f"What's the name of the {obj_name} you want to "
35-
"load? (Type '?' to get a list of them)",
36-
helper=named_objs_helper(storage, store_name))
37-
if name:
38-
try:
39-
obj = getattr(storage, store_name)[name]
40-
except Exception as e:
41-
wizard.exception("Something went wrong when loading "
42-
f"{name}. Maybe check the spelling?", e)
43-
return
44-
else:
45-
return obj
34+
# TODO: switch this to using wizard.ask_enumerate_dict, I think
35+
store = getattr(storage, store_name)
36+
options = {obj.name: obj for obj in store if obj.is_named}
37+
result = wizard.ask_enumerate_dict(
38+
f"What's the name of the {obj_name} you want to load?",
39+
options
40+
)
41+
return result
4642

4743
def load_from_ops(wizard, store_name, obj_name):
4844
wizard.say("Okay, we'll load it from an OPS file.")

0 commit comments

Comments
 (0)