Yield the lines for alias part of the help.
(self)
| 512 | print("\n".join(self.emit_alias_help())) |
| 513 | |
| 514 | def emit_alias_help(self) -> t.Generator[str, None, None]: |
| 515 | """Yield the lines for alias part of the help.""" |
| 516 | if not self.aliases: |
| 517 | return |
| 518 | |
| 519 | classdict: dict[str, type[Configurable]] = {} |
| 520 | for cls in self.classes: |
| 521 | # include all parents (up to, but excluding Configurable) in available names |
| 522 | for c in cls.mro()[:-3]: |
| 523 | classdict[c.__name__] = t.cast(t.Type[Configurable], c) |
| 524 | |
| 525 | fhelp: str | None |
| 526 | for alias, longname in self.aliases.items(): |
| 527 | try: |
| 528 | if isinstance(longname, tuple): |
| 529 | longname, fhelp = longname |
| 530 | else: |
| 531 | fhelp = None |
| 532 | classname, traitname = longname.split(".")[-2:] |
| 533 | longname = classname + "." + traitname |
| 534 | cls = classdict[classname] |
| 535 | |
| 536 | trait = cls.class_traits(config=True)[traitname] |
| 537 | fhelp_lines = cls.class_get_trait_help(trait, helptext=fhelp).splitlines() |
| 538 | |
| 539 | if not isinstance(alias, tuple): # type:ignore[unreachable] |
| 540 | alias = (alias,) # type:ignore[assignment] |
| 541 | alias = sorted(alias, key=len) # type:ignore[assignment] |
| 542 | alias = ", ".join(("--%s" if len(m) > 1 else "-%s") % m for m in alias) |
| 543 | |
| 544 | # reformat first line |
| 545 | fhelp_lines[0] = fhelp_lines[0].replace("--" + longname, alias) |
| 546 | yield from fhelp_lines |
| 547 | yield indent("Equivalent to: [--%s]" % longname) |
| 548 | except Exception as ex: |
| 549 | self.log.error("Failed collecting help-message for alias %r, due to: %s", alias, ex) |
| 550 | raise |
| 551 | |
| 552 | def print_flag_help(self) -> None: |
| 553 | """Print the flag part of the help.""" |