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

Function _handle_explain_cmd

explainshell/web/views.py:231–305  ·  view source on GitHub ↗
(url_distro, url_release)

Source from the content-addressed store, hash-verified

229
230
231def _handle_explain_cmd(url_distro, url_release):
232 if not request.args.get("cmd", "").strip():
233 return redirect("/")
234 command = request.args["cmd"].strip()
235 command = command[:1000]
236 if "\n" in command:
237 return render_template(
238 "errors/error.html", title="parsing error!", message="no newlines please"
239 )
240
241 prefix = _explain_prefix(url_distro, url_release)
242 if url_distro:
243 # Explicit URL distro — strict scoping, no fallback.
244 distro, release = url_distro, url_release
245 distro_preference = None
246 else:
247 # No explicit distro — let the preference list drive lookups.
248 distro, release = None, None
249 distro_preference = sorted(
250 get_distros(),
251 key=lambda dr: (dr[0] == "ubuntu", dr[1]),
252 reverse=True,
253 )
254 try:
255 matches, helptext, debug_info = explain_cmd(
256 command,
257 get_store(),
258 distro=distro,
259 release=release,
260 explain_prefix=prefix,
261 distro_preference=distro_preference,
262 )
263 helptext = [(render_markdown(text), id_) for text, id_ in helptext]
264
265 # Compute distros scoped to the matched commands (intersection).
266 cmd_names = [m["name"] for m in matches if "name" in m]
267 if cmd_names:
268 sets = [set(get_store().distros_for_name(n)) for n in cmd_names]
269 cmd_distros = sorted(sets[0].intersection(*sets[1:]))
270 else:
271 cmd_distros = list(get_distros())
272
273 body = render_template(
274 "explain.html",
275 matches=matches,
276 helptext=helptext,
277 getargs=command,
278 debug_info=debug_info,
279 available_distros=cmd_distros,
280 )
281 return _cacheable_explain_response(body)
282
283 except errors.ProgramDoesNotExist as error_msg:
284 return render_template(
285 "errors/missingmanpage.html", title="missing man page", e=error_msg
286 )
287 except bashlex.errors.ParsingError as error_msg:
288 logger.warning("%r parsing error: %s", command, error_msg.message)

Callers 1

explain_routerFunction · 0.85

Calls 7

get_distrosFunction · 0.90
get_storeFunction · 0.90
render_markdownFunction · 0.90
_explain_prefixFunction · 0.85
explain_cmdFunction · 0.85
distros_for_nameMethod · 0.80

Tested by

no test coverage detected