MCPcopy
hub / github.com/opentrace/opentrace / run_get_node

Function run_get_node

agent/src/opentrace_agent/cli/get_node.py:75–110  ·  view source on GitHub ↗

Entry point for the get-node subcommand. Raises ``click.ClickException`` when the node id is not in the graph — exit code 1 with a one-line stderr message, no traceback.

(node_id: str, db_path: str, *, output_json: bool = False)

Source from the content-addressed store, hash-verified

73
74
75def run_get_node(node_id: str, db_path: str, *, output_json: bool = False) -> None:
76 """Entry point for the get-node subcommand.
77
78 Raises ``click.ClickException`` when the node id is not in the
79 graph — exit code 1 with a one-line stderr message, no traceback.
80 """
81 from opentrace_agent.store import GraphStore
82
83 store = GraphStore(db_path, read_only=True)
84 try:
85 node = store.get_node(node_id)
86 if node is None:
87 raise click.ClickException(f"Node not found: {node_id}")
88
89 try:
90 raw = store.traverse(node_id, direction="both", max_depth=1)
91 except ValueError:
92 # store.traverse re-checks node existence and raises if it
93 # vanished between the get_node above and the traversal —
94 # treat as "no neighbors" rather than failing the whole call.
95 raw = []
96
97 neighbors = [_classify_neighbor(node_id, entry) for entry in raw]
98
99 if output_json:
100 click.echo(
101 json.dumps(
102 {"node": _node_to_dict(node), "neighbors": neighbors},
103 indent=2,
104 default=str,
105 )
106 )
107 else:
108 _emit_text(node, neighbors)
109 finally:
110 store.close()
111
112
113def _emit_text(node: dict[str, Any], neighbors: list[dict[str, Any]]) -> None:

Callers 1

get_node_cmdFunction · 0.90

Calls 7

get_nodeMethod · 0.95
traverseMethod · 0.95
closeMethod · 0.95
GraphStoreClass · 0.90
_classify_neighborFunction · 0.85
_node_to_dictFunction · 0.70
_emit_textFunction · 0.70

Tested by

no test coverage detected