diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 81079104a..8ca322078 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -792,7 +792,7 @@ class Application(QApplication): def exit(self, status): """Extend QApplication::exit to log the event.""" log.destroy.debug("Now calling QApplication::exit.") - if self._args.debug_exit: + if 'debug-exit' in self._args.debug_flags: if hunter is None: print("Not logging late shutdown because hunter could not be " "imported!", file=sys.stderr) diff --git a/qutebrowser/misc/crashsignal.py b/qutebrowser/misc/crashsignal.py index aa7438732..d8d8bb385 100644 --- a/qutebrowser/misc/crashsignal.py +++ b/qutebrowser/misc/crashsignal.py @@ -207,10 +207,10 @@ class CrashHandler(QObject): is_ignored_exception = (exctype is bdb.BdbQuit or not issubclass(exctype, Exception)) - if self._args.pdb_postmortem: + if 'pdb-postmortem' in self._args.debug_flags: pdb.post_mortem(tb) - if is_ignored_exception or self._args.pdb_postmortem: + if is_ignored_exception or 'pdb-postmortem' in self._args.debug_flags: # pdb exit, KeyboardInterrupt, ... status = 0 if is_ignored_exception else 2 try: diff --git a/qutebrowser/qutebrowser.py b/qutebrowser/qutebrowser.py index 8321fb04b..3ce11b07b 100644 --- a/qutebrowser/qutebrowser.py +++ b/qutebrowser/qutebrowser.py @@ -103,10 +103,6 @@ def get_argparser(): help="Silently remove unknown config options.") debug.add_argument('--nowindow', action='store_true', help="Don't show " "the main window.") - debug.add_argument('--debug-exit', help="Turn on debugging of late exit.", - action='store_true') - debug.add_argument('--pdb-postmortem', action='store_true', - help="Drop into pdb on exceptions.") debug.add_argument('--temp-basedir', action='store_true', help="Use a " "temporary basedir.") debug.add_argument('--no-err-windows', action='store_true', help="Don't " @@ -118,6 +114,9 @@ def get_argparser(): action='append') debug.add_argument('--qt-flag', help="Pass an argument to Qt as flag.", nargs=1, action='append') + debug.add_argument('--debug-flag', type=debug_flag_error, default=[], + help="Pass name of debugging feature to be turned on.", + nargs=1, action='append', dest='debug_flags') parser.add_argument('command', nargs='*', help="Commands to execute on " "startup.", metavar=':command') # URLs will actually be in command @@ -145,6 +144,22 @@ def logfilter_error(logfilter: str): logfilter, ', '.join(log.LOGGER_NAMES))) +def debug_flag_error(flag): + """Validate flags passed to --debug-flag. + + Available flags: + debug-exit: Turn on debugging of late exit. + pdb-postmortem: Drop into pdb on exceptions. + """ + valid_flags = ['debug-exit', 'pdb-postmortem'] + + if flag in valid_flags: + return flag + else: + raise argparse.ArgumentTypeError("Invalid flag - valid flags include: " + + str(valid_flags)) + + def main(): parser = get_argparser() if sys.platform == 'darwin' and getattr(sys, 'frozen', False):