Add an option to mitmproxy. Help should be a single paragraph with no linebreaks - it will be reflowed by tools. Information on the data type should be omitted - it will be generated and added by tools as needed.
(
self,
name: str,
typespec: type,
default: Any,
help: str,
choices: Sequence[str] | None = None,
)
| 68 | self.master = master |
| 69 | |
| 70 | def add_option( |
| 71 | self, |
| 72 | name: str, |
| 73 | typespec: type, |
| 74 | default: Any, |
| 75 | help: str, |
| 76 | choices: Sequence[str] | None = None, |
| 77 | ) -> None: |
| 78 | """ |
| 79 | Add an option to mitmproxy. |
| 80 | |
| 81 | Help should be a single paragraph with no linebreaks - it will be |
| 82 | reflowed by tools. Information on the data type should be omitted - |
| 83 | it will be generated and added by tools as needed. |
| 84 | """ |
| 85 | assert not isinstance(choices, str) |
| 86 | if name in self.master.options: |
| 87 | existing = self.master.options._options[name] |
| 88 | same_signature = ( |
| 89 | existing.name == name |
| 90 | and existing.typespec == typespec |
| 91 | and existing.default == default |
| 92 | and existing.help == help |
| 93 | and existing.choices == choices |
| 94 | ) |
| 95 | if same_signature: |
| 96 | return |
| 97 | else: |
| 98 | logger.warning("Over-riding existing option %s" % name) |
| 99 | self.master.options.add_option(name, typespec, default, help, choices) |
| 100 | |
| 101 | def add_command(self, path: str, func: Callable) -> None: |
| 102 | """Add a command to mitmproxy. |