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

Function explain_cmd

explainshell/web/views.py:462–575  ·  view source on GitHub ↗
(
    command,
    store,
    distro=None,
    release=None,
    explain_prefix="/explain",
    distro_preference=None,
)

Source from the content-addressed store, hash-verified

460
461
462def explain_cmd(
463 command,
464 store,
465 distro=None,
466 release=None,
467 explain_prefix="/explain",
468 distro_preference=None,
469):
470 matcher_ = matcher.Matcher(
471 command,
472 store,
473 distro=distro,
474 release=release,
475 distro_preference=distro_preference,
476 )
477 groups = matcher_.match()
478 expansions = matcher_.expansions
479
480 shell_group = groups[0]
481 cmd_groups = groups[1:]
482 matches = []
483
484 # save a mapping between the help text to its assigned id,
485 # we're going to reuse ids that have the same text
486 text_ids = {}
487
488 # remember where each assigned id has started in the source,
489 # we're going to use it later on to sort the help text by start
490 # position
491 id_start_pos = {}
492
493 logger.debug(f"processing {len(shell_group.results)} shell_group results ...")
494
495 ln = []
496 for m in shell_group.results:
497 cmd_class = shell_group.name
498 help_class = f"help-{len(text_ids)}"
499
500 text = str(m.text)
501 if len(text.replace("None", "")) > 0:
502 help_class = text_ids.setdefault(text, help_class)
503 else:
504 # unknowns in the shell group are possible when our parser left
505 # an unparsed remainder, see matcher._mark_unparsed_unknown
506 cmd_class += " unknown"
507 help_class = ""
508 if help_class:
509 id_start_pos.setdefault(help_class, m.start)
510
511 d = _make_match(m.start, m.end, m.match, cmd_class, help_class)
512 format_match(d, m, expansions, explain_prefix=explain_prefix)
513
514 ln.append(d)
515 matches.append(ln)
516
517 logger.debug(f"processing {len(cmd_groups)} cmd_group results ...")
518
519 for cmd_group in cmd_groups:

Callers 2

run_profileFunction · 0.90
_handle_explain_cmdFunction · 0.85

Calls 7

matchMethod · 0.95
has_nextMethod · 0.95
peekMethod · 0.95
_make_matchFunction · 0.85
format_matchFunction · 0.85
manpage_urlFunction · 0.85
nextFunction · 0.50

Tested by 1

run_profileFunction · 0.72