Return the help related to this CLI util
(self, cmd: Optional[str] = None)
| 3728 | print("Exited") |
| 3729 | |
| 3730 | def help(self, cmd: Optional[str] = None) -> None: |
| 3731 | """ |
| 3732 | Return the help related to this CLI util |
| 3733 | """ |
| 3734 | def _args(func: Any) -> str: |
| 3735 | flags = func._flags.copy() |
| 3736 | if func.__name__ in self.commands_output: |
| 3737 | flags += self.commands_output[func.__name__]._flags # type: ignore |
| 3738 | return " %s%s" % ( |
| 3739 | ( |
| 3740 | "%s " % " ".join("[%s]" % x for x in flags) |
| 3741 | if flags else "" |
| 3742 | ), |
| 3743 | " ".join( |
| 3744 | "<%s%s>" % ( |
| 3745 | x.name, |
| 3746 | "?" if |
| 3747 | (x.default is None or x.default != inspect.Parameter.empty) |
| 3748 | else "" |
| 3749 | ) |
| 3750 | for x in list(inspect.signature(func).parameters.values())[1:] |
| 3751 | if x.name not in func._flagnames and x.name[0] != "_" |
| 3752 | ) |
| 3753 | ) |
| 3754 | |
| 3755 | if cmd: |
| 3756 | if cmd not in self.commands: |
| 3757 | print("Unknown command '%s'" % cmd) |
| 3758 | return |
| 3759 | # help for one command |
| 3760 | func = self.commands[cmd] |
| 3761 | print("%s%s: %s" % ( |
| 3762 | cmd, |
| 3763 | _args(func), |
| 3764 | func.__doc__ and func.__doc__.strip() |
| 3765 | )) |
| 3766 | else: |
| 3767 | header = "│ %s - Help │" % self.__class__.__name__ |
| 3768 | print("┌" + "─" * (len(header) - 2) + "┐") |
| 3769 | print(header) |
| 3770 | print("└" + "─" * (len(header) - 2) + "┘") |
| 3771 | print( |
| 3772 | pretty_list( |
| 3773 | [ |
| 3774 | ( |
| 3775 | cmd, |
| 3776 | _args(func), |
| 3777 | func.__doc__ and func.__doc__.strip().split("\n")[0] or "" |
| 3778 | ) |
| 3779 | for cmd, func in self.commands.items() |
| 3780 | ], |
| 3781 | [("Command", "Arguments", "Description")] |
| 3782 | ) |
| 3783 | ) |
| 3784 | |
| 3785 | def _completer(self) -> 'prompt_toolkit.completion.Completer': |
| 3786 | """ |
no test coverage detected