MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / error

Method error

examples/custom_parser.py:26–43  ·  view source on GitHub ↗

Custom override that applies custom formatting to the error message.

(self, message: str)

Source from the content-addressed store, hash-verified

24 super().__init__(*args, **kwargs)
25
26 def error(self, message: str) -> NoReturn:
27 """Custom override that applies custom formatting to the error message."""
28 lines = message.split("\n")
29 formatted_message = ""
30 for linum, line in enumerate(lines):
31 if linum == 0:
32 formatted_message = "Error: " + line
33 else:
34 formatted_message += "\n " + line
35
36 self.print_usage(sys.stderr)
37
38 # Format errors with warning style
39 formatted_message = stylize(
40 formatted_message,
41 style=styles.WARNING,
42 )
43 self.exit(2, f"{formatted_message}\n\n")
44
45
46if __name__ == "__main__":

Calls 2

stylizeFunction · 0.90
print_usageMethod · 0.80