Skip to content

Turn complex codebases into clear, navigable architecture diagrams with Claude Code.

1.1 KB
Raw Blame
import { ensureOmmForRead, classExists } from '../lib/store.js';
import { getIncomingRefs, getOutgoingRefs } from '../lib/refs.js';

export function commandRefs(className: string, reverse: boolean): void {
  if (!ensureOmmForRead()) return;

  if (!classExists(className)) {
    process.stderr.write(`error: element '${className}' not found\n`);
    process.exit(1);
  }

  if (reverse) {
    // Show what this class references (outgoing)
    const refs = getOutgoingRefs(className);
    if (refs.length === 0) {
      process.stdout.write(`${className} does not reference any other element.\n`);
      return;
    }
    process.stdout.write(`${className} references:\n`);
    for (const ref of refs) {
      process.stdout.write(`  → ${ref.target_class}\n`);
    }
  } else {
    // Show what references this class (incoming)
    const refs = getIncomingRefs(className);
    if (refs.length === 0) {
      process.stdout.write(`No element references ${className}.\n`);
      return;
    }
    process.stdout.write(`Referenced by:\n`);
    for (const ref of refs) {
      process.stdout.write(`  ← ${ref.source_class}\n`);
    }
  }
}