Skip to content

Commit 0237a89

Browse files
committed
Patch argparse.ArgumentParser.error
Apply Monkey Patch for `argparse.ArgumentParser.error` to reduce redundant output. When using MI it's not necessary to ensure user readable.
1 parent f6540a6 commit 0237a89

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

bugzilla/_mi.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ def exit_patched(self, status=0, message=None):
126126
raise InterruptLoop
127127

128128

129+
def error_patched(self, message):
130+
""" A patch on `argparse.ArgumentParser`
131+
132+
Prepare for Monkey Patch on built-in
133+
`argparse.ArgumentParser` to fit MI.
134+
Later we would use just like `_print_message_patched`
135+
"""
136+
args = {'prog': self.prog, 'message': message}
137+
self.exit(2, '%(prog)s: error: %(message)s' % args)
138+
139+
129140
class Bugzilla_patched(bugzilla.Bugzilla):
130141
""" Patch `bugzilla.Bugzilla` to fit MI
131142
@@ -241,6 +252,7 @@ def setup_parser():
241252
"""
242253
argparse.ArgumentParser._print_message = _print_message_patched #Monkey Patch
243254
argparse.ArgumentParser.exit = exit_patched #Monkey Patch
255+
argparse.ArgumentParser.error = error_patched #Monkey Patch
244256
rootparser = _setup_root_parser()
245257
subparsers = rootparser.add_subparsers(dest="command")
246258
subparsers.required = True

0 commit comments

Comments
 (0)