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"),
)
| 1863 | |
| 1864 | @find_app.command("name") |
| 1865 | def find_by_name( |
| 1866 | ctx: typer.Context, |
| 1867 | name: str = typer.Argument(..., help="Name to search for"), |
| 1868 | type: Optional[str] = typer.Option(None, "--type", "-t", help="Filter by type (function, class, file, module)"), |
| 1869 | 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)."), |
| 1870 | visual: bool = typer.Option(False, "--visual", "--viz", "-V", help="Show results as interactive graph visualization"), |
| 1871 | context: Optional[str] = typer.Option(None, "--context", "-c", help="Specific context to use"), |
| 1872 | ): |
| 1873 | """ |
| 1874 | Find code elements by name. |
| 1875 | |
| 1876 | Fuzzy matching is enabled by default (configurable via the FUZZY_SEARCH |
| 1877 | config key, or per-invocation with --fuzzy / --no-fuzzy). |
| 1878 | |
| 1879 | Examples: |
| 1880 | cgc find name MyClass |
| 1881 | cgc find name calculate --type function |
| 1882 | cgc find name MyClass --no-fuzzy |
| 1883 | cgc find name MyClass --visual |
| 1884 | """ |
| 1885 | _load_credentials() |
| 1886 | services = _initialize_services(context) |
| 1887 | if not all(services[:3]): |
| 1888 | raise typer.Exit(code=1) |
| 1889 | db_manager, graph_builder, code_finder = services[:3] |
| 1890 | |
| 1891 | # Resolve effective fuzzy setting: CLI flag wins, else config, else true. |
| 1892 | if fuzzy is None: |
| 1893 | from codegraphcontext.cli.config_manager import load_config |
| 1894 | cfg_value = load_config().get("FUZZY_SEARCH", "true") |
| 1895 | fuzzy_search = str(cfg_value).strip().lower() == "true" |
| 1896 | else: |
| 1897 | fuzzy_search = fuzzy |
| 1898 | |
| 1899 | try: |
| 1900 | results = [] |
| 1901 | |
| 1902 | _VALID_FIND_TYPES = { |
| 1903 | 'all', 'function', 'class', 'variable', 'module', 'file', |
| 1904 | } |
| 1905 | if type is not None and type.lower() not in _VALID_FIND_TYPES: |
| 1906 | console.print( |
| 1907 | f"[bold red]Invalid --type '{type}'.[/bold red] " |
| 1908 | f"Must be one of: {', '.join(sorted(_VALID_FIND_TYPES))}" |
| 1909 | ) |
| 1910 | raise typer.Exit(code=1) |
| 1911 | |
| 1912 | # Search based on type filter |
| 1913 | if type is None or type.lower() == 'all': |
| 1914 | funcs = code_finder.find_by_function_name(name, fuzzy_search=fuzzy_search) |
| 1915 | classes = code_finder.find_by_class_name(name, fuzzy_search=fuzzy_search) |
| 1916 | variables = code_finder.find_by_variable_name(name) |
| 1917 | modules = code_finder.find_by_module_name(name) |
| 1918 | imports = code_finder.find_imports(name) |
| 1919 | |
| 1920 | for f in funcs: f['type'] = 'Function' |
| 1921 | for c in classes: c['type'] = 'Class' |
| 1922 | for v in variables: v['type'] = 'Variable' |
nothing calls this directly
no test coverage detected