| 460 | |
| 461 | |
| 462 | def 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: |