Created
March 30, 2024 23:01
-
-
Save ariel-co/64ab6256045b39ee42c61a32ef5d3680 to your computer and use it in GitHub Desktop.
argparser.ArgumentParser subclass that prints error message automatically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyArgParser(argparse.ArgumentParser): | |
| def error(self, message): | |
| print(f'Error: {message}\n', file=sys.stderr) | |
| self.print_help() | |
| sys.exit(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment