MCPcopy Index your code
hub / github.com/idank/explainshell / _discover_manpage_suggestions

Method _discover_manpage_suggestions

explainshell/store.py:351–401  ·  view source on GitHub ↗

find suggestions for a given man page source is the source path of the man page in question, existing is a list of (source, man page) of suggestions that were already discovered

(
        self,
        source: str,
        existing: list[tuple[str, ParsedManpage]],
        distro: str | None = None,
        release: str | None = None,
    )

Source from the content-addressed store, hash-verified

349 ]
350
351 def _discover_manpage_suggestions(
352 self,
353 source: str,
354 existing: list[tuple[str, ParsedManpage]],
355 distro: str | None = None,
356 release: str | None = None,
357 ) -> list[tuple[str, ParsedManpage]]:
358 """find suggestions for a given man page
359
360 source is the source path of the man page in question,
361 existing is a list of (source, man page) of suggestions that were
362 already discovered
363 """
364 skip = {src for src, m in existing}
365
366 # find all srcs that point to this source
367 src_rows = self._conn.execute(
368 "SELECT src FROM mappings WHERE dst = ?", (source,)
369 ).fetchall()
370 srcs = [row["src"] for row in src_rows]
371 if not srcs:
372 return []
373
374 # find all dsts of those srcs
375 placeholders = ",".join("?" * len(srcs))
376 dst_rows = self._conn.execute(
377 f"SELECT DISTINCT dst FROM mappings WHERE src IN ({placeholders})",
378 srcs,
379 ).fetchall()
380 suggestion_sources = [row["dst"] for row in dst_rows if row["dst"] not in skip]
381 if not suggestion_sources:
382 return []
383
384 # get just the name and source of found suggestions
385 placeholders = ",".join("?" * len(suggestion_sources))
386 manpage_rows = self._conn.execute(
387 f"SELECT name, source FROM parsed_manpages WHERE source IN ({placeholders})",
388 suggestion_sources,
389 ).fetchall()
390
391 # Apply distro/release filter when requested
392 if distro is not None and release is not None:
393 prefix = f"{distro}/{release}/"
394 manpage_rows = [
395 row for row in manpage_rows if row["source"].startswith(prefix)
396 ]
397
398 return [
399 (row["source"], ParsedManpage(source=row["source"], name=row["name"]))
400 for row in manpage_rows
401 ]
402
403 def distros(self) -> list[tuple[str, str]]:
404 """Return distinct (distro, release) pairs from manpages."""

Callers 1

find_man_pageMethod · 0.95

Calls 1

ParsedManpageClass · 0.90

Tested by

no test coverage detected