Add -s argument to set temporary options.

This commit is contained in:
Florian Bruhin 2015-02-05 07:54:19 +01:00
parent 5ed592a447
commit 7615e20091
3 changed files with 20 additions and 8 deletions

View File

@ -39,7 +39,7 @@ from PyQt5.QtCore import (pyqtSlot, qInstallMessageHandler, QTimer, QUrl,
import qutebrowser import qutebrowser
import qutebrowser.resources # pylint: disable=unused-import import qutebrowser.resources # pylint: disable=unused-import
from qutebrowser.commands import cmdutils, runners from qutebrowser.commands import cmdutils, runners
from qutebrowser.config import style, config, websettings from qutebrowser.config import style, config, websettings, configexc
from qutebrowser.browser import quickmarks, cookies, cache, adblock, history from qutebrowser.browser import quickmarks, cookies, cache, adblock, history
from qutebrowser.browser.network import qutescheme, proxy from qutebrowser.browser.network import qutescheme, proxy
from qutebrowser.mainwindow import mainwindow from qutebrowser.mainwindow import mainwindow
@ -136,7 +136,7 @@ class Application(QApplication):
"Error while initializing: {}".format(e)) "Error while initializing: {}".format(e))
msgbox.exec_() msgbox.exec_()
sys.exit(1) sys.exit(1)
QTimer.singleShot(0, self._open_pages) QTimer.singleShot(0, self._process_args)
log.init.debug("Initializing eventfilter...") log.init.debug("Initializing eventfilter...")
self._event_filter = modeman.EventFilter(self) self._event_filter = modeman.EventFilter(self)
@ -252,14 +252,21 @@ class Application(QApplication):
else: else:
earlyinit.init_faulthandler(self._crashlogfile) earlyinit.init_faulthandler(self._crashlogfile)
def _open_pages(self): def _process_args(self):
"""Open startpage etc. and process commandline args.""" """Open startpage etc. and process commandline args."""
self.process_args(self._args.command) config_obj = objreg.get('config')
for sect, opt, val in self._args.temp_settings:
try:
config_obj.set('temp', sect, opt, val)
except (configexc.Error, configparser.Error) as e:
message.error('current', "set: {} - {}".format(
e.__class__.__name__, e))
self.process_pos_args(self._args.command)
self._open_startpage() self._open_startpage()
self._open_quickstart() self._open_quickstart()
def _get_window(self, via_ipc, force_window=False, force_tab=False): def _get_window(self, via_ipc, force_window=False, force_tab=False):
"""Helper function for process_args to get a window id. """Helper function for process_pos_args to get a window id.
Args: Args:
via_ipc: Whether the request was made via IPC. via_ipc: Whether the request was made via IPC.
@ -299,8 +306,8 @@ class Application(QApplication):
self.alert(window_to_raise) self.alert(window_to_raise)
return win_id return win_id
def process_args(self, args, via_ipc=False, cwd=None): def process_pos_args(self, args, via_ipc=False, cwd=None):
"""Process commandline args. """Process positional commandline args.
URLs to open have no prefix, commands to execute begin with a colon. URLs to open have no prefix, commands to execute begin with a colon.

View File

@ -158,7 +158,7 @@ class IPCServer(QObject):
return return
cwd = json_data.get('cwd', None) cwd = json_data.get('cwd', None)
app = objreg.get('app') app = objreg.get('app')
app.process_args(args, via_ipc=True, cwd=cwd) app.process_pos_args(args, via_ipc=True, cwd=cwd)
@pyqtSlot() @pyqtSlot()
def on_timeout(self): def on_timeout(self):

View File

@ -49,6 +49,11 @@ def get_argparser():
"for no config storage)") "for no config storage)")
parser.add_argument('-V', '--version', help="Show version and quit.", parser.add_argument('-V', '--version', help="Show version and quit.",
action='store_true') action='store_true')
parser.add_argument('-s', '--set', help="Set a temporary setting for "
"this session", nargs=3, action='append',
dest='temp_settings', default=[],
metavar=('SECTION', 'OPTION', 'VALUE'))
debug = parser.add_argument_group('debug arguments') debug = parser.add_argument_group('debug arguments')
debug.add_argument('-l', '--loglevel', dest='loglevel', debug.add_argument('-l', '--loglevel', dest='loglevel',
help="Set loglevel", default='info') help="Set loglevel", default='info')