Merge :wq into :quit and add an alias
This commit is contained in:
parent
065f82f485
commit
94ac2ca56c
@ -642,7 +642,25 @@ class Quitter:
|
|||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@cmdutils.register(instance='quitter', name='quit', ignore_args=True)
|
@cmdutils.register(instance='quitter', name='quit')
|
||||||
|
@cmdutils.argument('session', completion=usertypes.Completion.sessions)
|
||||||
|
def quit(self, save=False, session=None):
|
||||||
|
"""Quit qutebrowser.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
save: When given, save the open windows even if auto_save.session is
|
||||||
|
turned off.
|
||||||
|
session: The name of the session to save.
|
||||||
|
"""
|
||||||
|
if session is not None and not save:
|
||||||
|
raise cmdexc.CommandError("Session name given without --save!")
|
||||||
|
if save:
|
||||||
|
if session is None:
|
||||||
|
session = sessions.default
|
||||||
|
self.shutdown(session=session)
|
||||||
|
else:
|
||||||
|
self.shutdown()
|
||||||
|
|
||||||
def shutdown(self, status=0, session=None, last_window=False,
|
def shutdown(self, status=0, session=None, last_window=False,
|
||||||
restart=False):
|
restart=False):
|
||||||
"""Quit qutebrowser.
|
"""Quit qutebrowser.
|
||||||
|
@ -90,7 +90,7 @@ class Command:
|
|||||||
|
|
||||||
def __init__(self, *, handler, name, instance=None, maxsplit=None,
|
def __init__(self, *, handler, name, instance=None, maxsplit=None,
|
||||||
hide=False, modes=None, not_modes=None, debug=False,
|
hide=False, modes=None, not_modes=None, debug=False,
|
||||||
ignore_args=False, deprecated=False, no_cmd_split=False,
|
deprecated=False, no_cmd_split=False,
|
||||||
star_args_optional=False, scope='global', backend=None,
|
star_args_optional=False, scope='global', backend=None,
|
||||||
no_replace_variables=False):
|
no_replace_variables=False):
|
||||||
# I really don't know how to solve this in a better way, I tried.
|
# I really don't know how to solve this in a better way, I tried.
|
||||||
@ -121,7 +121,6 @@ class Command:
|
|||||||
self._scope = scope
|
self._scope = scope
|
||||||
self._star_args_optional = star_args_optional
|
self._star_args_optional = star_args_optional
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
self.ignore_args = ignore_args
|
|
||||||
self.handler = handler
|
self.handler = handler
|
||||||
self.no_cmd_split = no_cmd_split
|
self.no_cmd_split = no_cmd_split
|
||||||
self.backend = backend
|
self.backend = backend
|
||||||
@ -225,33 +224,31 @@ class Command:
|
|||||||
else:
|
else:
|
||||||
self.desc = ""
|
self.desc = ""
|
||||||
|
|
||||||
if not self.ignore_args:
|
for param in signature.parameters.values():
|
||||||
for param in signature.parameters.values():
|
# https://docs.python.org/3/library/inspect.html#inspect.Parameter.kind
|
||||||
# https://docs.python.org/3/library/inspect.html#inspect.Parameter.kind
|
# "Python has no explicit syntax for defining positional-only
|
||||||
# "Python has no explicit syntax for defining positional-only
|
# parameters, but many built-in and extension module functions
|
||||||
# parameters, but many built-in and extension module functions
|
# (especially those that accept only one or two parameters) accept
|
||||||
# (especially those that accept only one or two parameters)
|
# them."
|
||||||
# accept them."
|
assert param.kind != inspect.Parameter.POSITIONAL_ONLY
|
||||||
assert param.kind != inspect.Parameter.POSITIONAL_ONLY
|
if param.name == 'self':
|
||||||
if param.name == 'self':
|
continue
|
||||||
continue
|
if self._inspect_special_param(param):
|
||||||
if self._inspect_special_param(param):
|
continue
|
||||||
continue
|
if (param.kind == inspect.Parameter.KEYWORD_ONLY and
|
||||||
if (param.kind == inspect.Parameter.KEYWORD_ONLY and
|
param.default is inspect.Parameter.empty):
|
||||||
param.default is inspect.Parameter.empty):
|
raise TypeError("{}: handler has keyword only argument {!r} "
|
||||||
raise TypeError("{}: handler has keyword only argument "
|
"without default!".format(
|
||||||
"{!r} without default!".format(self.name,
|
self.name, param.name))
|
||||||
param.name))
|
typ = self._get_type(param)
|
||||||
typ = self._get_type(param)
|
is_bool = typ is bool
|
||||||
is_bool = typ is bool
|
kwargs = self._param_to_argparse_kwargs(param, is_bool)
|
||||||
kwargs = self._param_to_argparse_kwargs(param, is_bool)
|
args = self._param_to_argparse_args(param, is_bool)
|
||||||
args = self._param_to_argparse_args(param, is_bool)
|
callsig = debug_utils.format_call(self.parser.add_argument, args,
|
||||||
callsig = debug_utils.format_call(
|
kwargs, full=False)
|
||||||
self.parser.add_argument, args, kwargs,
|
log.commands.vdebug('Adding arg {} of type {} -> {}'.format(
|
||||||
full=False)
|
param.name, typ, callsig))
|
||||||
log.commands.vdebug('Adding arg {} of type {} -> {}'.format(
|
self.parser.add_argument(*args, **kwargs)
|
||||||
param.name, typ, callsig))
|
|
||||||
self.parser.add_argument(*args, **kwargs)
|
|
||||||
return signature.parameters.values()
|
return signature.parameters.values()
|
||||||
|
|
||||||
def _param_to_argparse_kwargs(self, param, is_bool):
|
def _param_to_argparse_kwargs(self, param, is_bool):
|
||||||
@ -453,12 +450,6 @@ class Command:
|
|||||||
kwargs = {}
|
kwargs = {}
|
||||||
signature = inspect.signature(self.handler)
|
signature = inspect.signature(self.handler)
|
||||||
|
|
||||||
if self.ignore_args:
|
|
||||||
if self._instance is not None:
|
|
||||||
param = list(signature.parameters.values())[0]
|
|
||||||
self._get_self_arg(win_id, param, args)
|
|
||||||
return args, kwargs
|
|
||||||
|
|
||||||
for i, param in enumerate(signature.parameters.values()):
|
for i, param in enumerate(signature.parameters.values()):
|
||||||
arg_info = self.get_arg_info(param)
|
arg_info = self.get_arg_info(param)
|
||||||
if i == 0 and self._instance is not None:
|
if i == 0 and self._instance is not None:
|
||||||
|
@ -4,6 +4,7 @@ aliases:
|
|||||||
default:
|
default:
|
||||||
w: session-save
|
w: session-save
|
||||||
q: quit
|
q: quit
|
||||||
|
wq: quit --save
|
||||||
type:
|
type:
|
||||||
name: Dict
|
name: Dict
|
||||||
keytype:
|
keytype:
|
||||||
|
Loading…
Reference in New Issue
Block a user