MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / find_by_name

Function find_by_name

src/codegraphcontext/cli/main.py:1682–1816  ·  view source on GitHub ↗

Find code elements by name. Fuzzy matching is enabled by default (configurable via the FUZZY_SEARCH config key, or per-invocation with --fuzzy / --no-fuzzy). Examples: cgc find name MyClass cgc find name calculate --type function cgc find name MyClass --no-

(
    ctx: typer.Context,
    name: str = typer.Argument(..., help="Name to search for"),
    type: Optional[str] = typer.Option(None, "--type", "-t", help="Filter by type (function, class, file, module)"),
    fuzzy: Optional[bool] = typer.Option(None, "--fuzzy/--no-fuzzy", help="Enable/disable fuzzy matching for this command. Overrides the FUZZY_SEARCH config value (default: true)."),
    visual: bool = typer.Option(False, "--visual", "--viz", "-V", help="Show results as interactive graph visualization"),
    context: Optional[str] = typer.Option(None, "--context", "-c", help="Specific context to use"),
)

Source from the content-addressed store, hash-verified

1680
1681@find_app.command("name")
1682def find_by_name(
1683 ctx: typer.Context,
1684 name: str = typer.Argument(..., help="Name to search for"),
1685 type: Optional[str] = typer.Option(None, "--type", "-t", help="Filter by type (function, class, file, module)"),
1686 fuzzy: Optional[bool] = typer.Option(None, "--fuzzy/--no-fuzzy", help="Enable/disable fuzzy matching for this command. Overrides the FUZZY_SEARCH config value (default: true)."),
1687 visual: bool = typer.Option(False, "--visual", "--viz", "-V", help="Show results as interactive graph visualization"),
1688 context: Optional[str] = typer.Option(None, "--context", "-c", help="Specific context to use"),
1689):
1690 """
1691 Find code elements by name.
1692
1693 Fuzzy matching is enabled by default (configurable via the FUZZY_SEARCH
1694 config key, or per-invocation with --fuzzy / --no-fuzzy).
1695
1696 Examples:
1697 cgc find name MyClass
1698 cgc find name calculate --type function
1699 cgc find name MyClass --no-fuzzy
1700 cgc find name MyClass --visual
1701 """
1702 _load_credentials()
1703 services = _initialize_services(context)
1704 if not all(services[:3]):
1705 raise typer.Exit(code=1)
1706 db_manager, graph_builder, code_finder = services[:3]
1707
1708 # Resolve effective fuzzy setting: CLI flag wins, else config, else true.
1709 if fuzzy is None:
1710 from codegraphcontext.cli.config_manager import load_config
1711 cfg_value = load_config().get("FUZZY_SEARCH", "true")
1712 fuzzy_search = str(cfg_value).strip().lower() == "true"
1713 else:
1714 fuzzy_search = fuzzy
1715
1716 try:
1717 results = []
1718
1719 _VALID_FIND_TYPES = {
1720 'all', 'function', 'class', 'variable', 'module', 'file',
1721 }
1722 if type is not None and type.lower() not in _VALID_FIND_TYPES:
1723 console.print(
1724 f"[bold red]Invalid --type '{type}'.[/bold red] "
1725 f"Must be one of: {', '.join(sorted(_VALID_FIND_TYPES))}"
1726 )
1727 raise typer.Exit(code=1)
1728
1729 # Search based on type filter
1730 if type is None or type.lower() == 'all':
1731 funcs = code_finder.find_by_function_name(name, fuzzy_search=fuzzy_search)
1732 classes = code_finder.find_by_class_name(name, fuzzy_search=fuzzy_search)
1733 variables = code_finder.find_by_variable_name(name)
1734 modules = code_finder.find_by_module_name(name)
1735 imports = code_finder.find_imports(name)
1736
1737 for f in funcs: f['type'] = 'Function'
1738 for c in classes: c['type'] = 'Class'
1739 for v in variables: v['type'] = 'Variable'

Callers

nothing calls this directly

Calls 15

load_configFunction · 0.90
_load_credentialsFunction · 0.85
_initialize_servicesFunction · 0.85
check_visual_flagFunction · 0.85
visualize_search_resultsFunction · 0.85
printMethod · 0.80
add_columnMethod · 0.80
add_rowMethod · 0.80
getMethod · 0.65
appendMethod · 0.65
find_by_function_nameMethod · 0.45
find_by_class_nameMethod · 0.45

Tested by

no test coverage detected