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

Function explain_router

explainshell/web/views.py:179–228  ·  view source on GitHub ↗

Unified router that handles all /explain/* URLs. Path disambiguation: - With ?cmd=: 0 segments = no distro, 2 segments = distro/release - Without ?cmd=: 1=program, 2=section/program, 3=distro/release/program, 4=distro/release/section/program

(path)

Source from the content-addressed store, hash-verified

177@bp.route("/explain", defaults={"path": ""})
178@bp.route("/explain/<path:path>")
179def explain_router(path):
180 """Unified router that handles all /explain/* URLs.
181
182 Path disambiguation:
183 - With ?cmd=: 0 segments = no distro, 2 segments = distro/release
184 - Without ?cmd=: 1=program, 2=section/program, 3=distro/release/program,
185 4=distro/release/section/program
186 """
187 parts = [p for p in path.split("/") if p] if path else []
188 has_cmd = "cmd" in request.args
189
190 url_distro = None
191 url_release = None
192 section = None
193 program = None
194
195 if has_cmd:
196 if len(parts) == 0:
197 pass # no distro
198 elif len(parts) == 2 and _is_known_distro(parts[0]):
199 url_distro, url_release = parts[0], parts[1]
200 else:
201 # invalid path with ?cmd
202 return redirect("/")
203 else:
204 if len(parts) == 0:
205 return redirect("/")
206 elif len(parts) == 1:
207 program = parts[0]
208 elif len(parts) == 2:
209 if _is_known_distro(parts[0]):
210 # /explain/ubuntu/26.04 with no ?cmd → redirect to index
211 return redirect("/")
212 section, program = parts[0], parts[1]
213 elif len(parts) == 3 and _is_known_distro(parts[0]):
214 url_distro, url_release, program = parts[0], parts[1], parts[2]
215 elif len(parts) == 4 and _is_known_distro(parts[0]):
216 url_distro, url_release, section, program = (
217 parts[0],
218 parts[1],
219 parts[2],
220 parts[3],
221 )
222 else:
223 return redirect("/")
224
225 if has_cmd:
226 return _handle_explain_cmd(url_distro, url_release)
227 else:
228 return _handle_explain_program(section, program, url_distro, url_release)
229
230
231def _handle_explain_cmd(url_distro, url_release):

Callers

nothing calls this directly

Calls 3

_is_known_distroFunction · 0.85
_handle_explain_cmdFunction · 0.85
_handle_explain_programFunction · 0.85

Tested by

no test coverage detected