mirror of
https://github.com/python/cpython.git
synced 2024-11-24 18:34:43 +08:00
bpo-37908: Add an example of ArgumentParser.exit() (GH-15455)
Co-Authored-By: Brandt Bucher <brandtbucher@gmail.com>
This commit is contained in:
parent
4210ad5ebd
commit
b1a2abdb06
@ -2029,7 +2029,14 @@ Exiting methods
|
||||
.. method:: ArgumentParser.exit(status=0, message=None)
|
||||
|
||||
This method terminates the program, exiting with the specified *status*
|
||||
and, if given, it prints a *message* before that.
|
||||
and, if given, it prints a *message* before that. The user can override
|
||||
this method to handle these steps differently::
|
||||
|
||||
class ErrorCatchingArgumentParser(argparse.ArgumentParser):
|
||||
def exit(self, status=0, message=None):
|
||||
if status:
|
||||
raise Exception(f'Exiting because of an error: {message}')
|
||||
exit(status)
|
||||
|
||||
.. method:: ArgumentParser.error(message)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user