diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 264cc4c3f..4b8ce897a 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -78,8 +78,8 @@ class Application(QApplication): networkmanager: The global NetworkManager instance. cookiejar: The global CookieJar instance. rl_bridge: The ReadlineBridge being used. + args: ArgumentParser instance. _keyparsers: A mapping from modes to keyparsers. - _args: ArgumentParser instance. _timers: List of used QTimers so they don't get GCed. _shutting_down: True if we're currently shutting down. _quit_status: The current quitting status. @@ -121,7 +121,7 @@ class Application(QApplication): sys.excepthook = self._exception_hook - self._args = args + self.args = args self._init_misc() actute_warning() self._init_config() @@ -155,12 +155,12 @@ class Application(QApplication): def _init_config(self): """Inizialize and read the config.""" - if self._args.confdir is None: + if self.args.confdir is None: confdir = get_standard_dir(QStandardPaths.ConfigLocation) - elif self._args.confdir == '': + elif self.args.confdir == '': confdir = None else: - confdir = self._args.confdir + confdir = self.args.confdir try: self.config = ConfigManager(confdir, 'qutebrowser.conf') except (config.ValidationError, @@ -210,7 +210,7 @@ class Application(QApplication): def _init_misc(self): """Initialize misc things.""" - if self._args.version: + if self.args.version: print(version.version()) print() print() @@ -285,7 +285,7 @@ class Application(QApplication): self.processEvents(QEventLoop.ExcludeUserInputEvents | QEventLoop.ExcludeSocketNotifiers) - for e in self._args.command: + for e in self.args.command: if e.startswith(':'): log.init.debug("Startup cmd {}".format(e)) self.commandmanager.run_safely_init(e.lstrip(':')) @@ -516,7 +516,7 @@ class Application(QApplication): # if shutdown: # self.shutdown() - @cmdutils.register(instance='', split=False) + @cmdutils.register(instance='', split=False, debug=True) def pyeval(self, s): """Evaluate a python string and display the results as a webpage. @@ -602,7 +602,7 @@ class Application(QApplication): self.quit() -@cmdutils.register(hide=True) +@cmdutils.register(debug=True) def crash(typ='exception'): """Crash for debugging purposes. diff --git a/qutebrowser/commands/command.py b/qutebrowser/commands/command.py index 72965a99c..f5cbb95a0 100644 --- a/qutebrowser/commands/command.py +++ b/qutebrowser/commands/command.py @@ -42,6 +42,7 @@ class Command: handler: The handler function to call. completion: Completions to use for arguments, as a list of strings. needs_js: Whether the command needs javascript enabled + debug: Whether this is a debugging command (only shown with --debug). """ # TODO: @@ -49,7 +50,7 @@ class Command: # this might be combined with help texts or so as well def __init__(self, name, split, hide, nargs, count, desc, instance, - handler, completion, modes, not_modes, needs_js): + handler, completion, modes, not_modes, needs_js, debug): # I really don't know how to solve this in a better way, I tried. # pylint: disable=too-many-arguments super().__init__() @@ -65,6 +66,7 @@ class Command: self.modes = modes self.not_modes = not_modes self.needs_js = needs_js + self.debug = debug def check(self, args): """Check if the argument count is valid and the command is permitted. diff --git a/qutebrowser/commands/utils.py b/qutebrowser/commands/utils.py index 1dfdeae26..198d22b93 100644 --- a/qutebrowser/commands/utils.py +++ b/qutebrowser/commands/utils.py @@ -104,11 +104,12 @@ class register: # pylint: disable=invalid-name strings. modes/not_modes: List of modes to use/not use. needs_js: If javascript is needed for this command. + debug: Whether this is a debugging command (only shown with --debug). """ def __init__(self, instance=None, name=None, nargs=None, split=True, hide=False, completion=None, modes=None, not_modes=None, - needs_js=False): + needs_js=False, debug=False): """Save decorator arguments. Gets called on parse-time with the decorator arguments. @@ -127,6 +128,7 @@ class register: # pylint: disable=invalid-name self.modes = modes self.not_modes = not_modes self.needs_js = needs_js + self.debug = debug def __call__(self, func): """Register the command before running the function. @@ -169,7 +171,8 @@ class register: # pylint: disable=invalid-name hide=self.hide, nargs=nargs, count=count, desc=desc, instance=self.instance, handler=func, completion=self.completion, modes=self.modes, - not_modes=self.not_modes, needs_js=self.needs_js) + not_modes=self.not_modes, needs_js=self.needs_js, + debug=self.debug) for name in names: cmd_dict[name] = cmd return func diff --git a/qutebrowser/models/completion.py b/qutebrowser/models/completion.py index 015d0094b..8e16bcae6 100644 --- a/qutebrowser/models/completion.py +++ b/qutebrowser/models/completion.py @@ -17,7 +17,7 @@ """CompletionModels for different usages.""" -from PyQt5.QtCore import pyqtSlot, Qt +from PyQt5.QtCore import pyqtSlot, Qt, QCoreApplication import qutebrowser.config.config as config import qutebrowser.config.configdata as configdata @@ -128,7 +128,10 @@ class CommandCompletionModel(BaseCompletionModel): assert cmd_dict cmdlist = [] for obj in set(cmd_dict.values()): - if not obj.hide: + if obj.hide or (obj.debug and not + QCoreApplication.instance().args.debug): + pass + else: cmdlist.append((obj.name, obj.desc)) for name, cmd in config.section('aliases').items(): cmdlist.append((name, "Alias for '{}'".format(cmd))) diff --git a/qutebrowser/utils/debug.py b/qutebrowser/utils/debug.py index 45215b7db..204de2262 100644 --- a/qutebrowser/utils/debug.py +++ b/qutebrowser/utils/debug.py @@ -49,7 +49,7 @@ def log_events(klass): return klass -@cmdutils.register(hide=True) +@cmdutils.register(debug=True) def set_trace(): """Set a tracepoint in the Python debugger that works with Qt.