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)
| 73 | |
| 74 | |
| 75 | def 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 | |
| 113 | def _emit_text(node: dict[str, Any], neighbors: list[dict[str, Any]]) -> None: |
no test coverage detected