MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / pick_instance

Function pick_instance

misc/python/materialize/cli/scratch/__init__.py:45–72  ·  view source on GitHub ↗

Show running instances and let the user pick one.

()

Source from the content-addressed store, hash-verified

43
44
45def pick_instance() -> Instance:
46 """Show running instances and let the user pick one."""
47 from materialize.scratch import print_instances
48
49 instances = list_all_instances()
50 active = [
51 i
52 for i in instances
53 if i.state and i.state["Name"] in ("running", "pending", "stopping", "stopped")
54 ]
55
56 if not active:
57 raise RuntimeError("No active instances found.")
58
59 if len(active) == 1:
60 return active[0]
61
62 print_instances(active, numbered=True)
63
64 while True:
65 choice = input("Select an instance [#]: ").strip()
66 try:
67 idx = int(choice)
68 if 1 <= idx <= len(active):
69 return active[idx - 1]
70 except ValueError:
71 pass
72 print(f"Invalid choice: {choice!r}. Enter a number 1-{len(active)}.")

Callers 2

runFunction · 0.90
runFunction · 0.90

Calls 2

print_instancesFunction · 0.90
list_all_instancesFunction · 0.85

Tested by

no test coverage detected