Argparse Wrapper. This class wraps argparse, adding the ability to make --help less verbose, and request help on specific subcategories at a time, eg 'certbot --help security' for security options.
| 33 | |
| 34 | |
| 35 | class HelpfulArgumentParser: |
| 36 | """Argparse Wrapper. |
| 37 | |
| 38 | This class wraps argparse, adding the ability to make --help less |
| 39 | verbose, and request help on specific subcategories at a time, eg |
| 40 | 'certbot --help security' for security options. |
| 41 | |
| 42 | """ |
| 43 | def __init__(self, args: list[str], plugins: Iterable[str]) -> None: |
| 44 | from certbot._internal import main |
| 45 | self.VERBS = { |
| 46 | "auth": main.certonly, |
| 47 | "certonly": main.certonly, |
| 48 | "run": main.run, |
| 49 | "install": main.install, |
| 50 | "plugins": main.plugins_cmd, |
| 51 | "register": main.register, |
| 52 | "update_account": main.update_account, |
| 53 | "show_account": main.show_account, |
| 54 | "unregister": main.unregister, |
| 55 | "renew": main.renew, |
| 56 | "revoke": main.revoke, |
| 57 | "rollback": main.rollback, |
| 58 | "everything": main.run, |
| 59 | "certificates": main.certificates, |
| 60 | "delete": main.delete, |
| 61 | "enhance": main.enhance, |
| 62 | "reconfigure": main.reconfigure, |
| 63 | } |
| 64 | |
| 65 | # Get notification function for printing |
| 66 | self.notify = display_obj.NoninteractiveDisplay(sys.stdout).notification |
| 67 | |
| 68 | self.actions: list[configargparse.Action] = [] |
| 69 | |
| 70 | # List of topics for which additional help can be provided |
| 71 | HELP_TOPICS: list[Optional[str]] = ["all", "security", "paths", "automation", "testing"] |
| 72 | HELP_TOPICS += list(self.VERBS) + self.COMMANDS_TOPICS + ["manage"] |
| 73 | |
| 74 | plugin_names: list[Optional[str]] = list(plugins) |
| 75 | self.help_topics: list[Optional[str]] = HELP_TOPICS + plugin_names + [None] |
| 76 | |
| 77 | self.args = args |
| 78 | |
| 79 | if self.args and self.args[0] == 'help': |
| 80 | self.args[0] = '--help' |
| 81 | |
| 82 | self.determine_verb() |
| 83 | help1 = self.prescan_for_flag("-h", self.help_topics) |
| 84 | help2 = self.prescan_for_flag("--help", self.help_topics) |
| 85 | self.help_arg: Union[str, bool] |
| 86 | if isinstance(help1, bool) and isinstance(help2, bool): |
| 87 | self.help_arg = help1 or help2 |
| 88 | else: |
| 89 | self.help_arg = help1 if isinstance(help1, str) else help2 |
| 90 | |
| 91 | short_usage = self._usage_string(plugins, self.help_arg) |
| 92 |
no outgoing calls