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

Method find_man_page

explainshell/store.py:151–254  ·  view source on GitHub ↗

find a man page by its name, everything following the last dot (.) in name, is taken as the section of the man page we return the man page found with the highest score, and a list of suggestions that also matched the given name (only the first item is prepopulated wi

(
        self, name: str, distro: str | None = None, release: str | None = None
    )

Source from the content-addressed store, hash-verified

149 self._conn.commit()
150
151 def find_man_page(
152 self, name: str, distro: str | None = None, release: str | None = None
153 ) -> list[ParsedManpage]:
154 """find a man page by its name, everything following the last dot (.) in name,
155 is taken as the section of the man page
156
157 we return the man page found with the highest score, and a list of
158 suggestions that also matched the given name (only the first item
159 is prepopulated with the option data)
160
161 when distro and release are set, filter results to manpages whose
162 source starts with ``distro/release/``."""
163 if name.endswith(".gz"):
164 logger.debug("name ends with .gz, looking up an exact match by source")
165 row = self._conn.execute(
166 "SELECT * FROM parsed_manpages WHERE source = ?", (name,)
167 ).fetchone()
168 if not row:
169 raise errors.ProgramDoesNotExist(name)
170 m = ParsedManpage.from_store(dict(row))
171 logger.debug("returning %s", m)
172 return [m]
173
174 section = None
175 orig_name = name
176
177 # don't try to look for a section if it's . (source)
178 if name != ".":
179 splitted = name.rsplit(".", 1)
180 name = splitted[0]
181 if len(splitted) > 1:
182 section = splitted[1]
183
184 logger.debug("looking up manpage in mappings with src %r", name)
185 mapping_rows = self._conn.execute(
186 "SELECT dst, score FROM mappings WHERE src = ?", (name,)
187 ).fetchall()
188
189 if not mapping_rows:
190 raise errors.ProgramDoesNotExist(name)
191
192 dsts = {row["dst"]: row["score"] for row in mapping_rows}
193
194 placeholders = ",".join("?" * len(dsts))
195 manpage_rows = self._conn.execute(
196 f"SELECT name, source FROM parsed_manpages WHERE source IN ({placeholders})",
197 list(dsts.keys()),
198 ).fetchall()
199
200 if len(manpage_rows) != len(dsts):
201 logger.error(
202 "one of %r mappings is missing in parsed_manpages table "
203 "(%d mappings, %d found)",
204 dsts,
205 len(dsts),
206 len(manpage_rows),
207 )
208

Callers 15

show_manpageFunction · 0.95
find_man_pagesMethod · 0.45
on_resultFunction · 0.45
explain_programFunction · 0.45
test_unicodeMethod · 0.45
test_no_optionsMethod · 0.45
test_known_argMethod · 0.45

Calls 3

ParsedManpageClass · 0.90
from_storeMethod · 0.80