Use @cmdutils.argument to hide arguments
This commit is contained in:
parent
2fc4f408cd
commit
c14db202d6
@ -456,6 +456,7 @@ The following arguments are supported for `@cmdutils.argument`:
|
||||
- `flag`: Customize the short flag (`-x`) the argument will get.
|
||||
- `win_id=True`: Mark the argument as special window ID argument
|
||||
- `count=True`: Mark the argument as special count argument
|
||||
- `hide=True`: Hide the argument from the documentation
|
||||
|
||||
The name of an argument will always be the parameter name, with any trailing
|
||||
underscores stripped.
|
||||
|
@ -1198,8 +1198,8 @@ class CommandDispatcher:
|
||||
cur.inspector.show()
|
||||
|
||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||
def download(self, url=None, dest_old: {'hide': True}=None, *,
|
||||
mhtml_=False, dest=None):
|
||||
@cmdutils.argument('dest_old', hide=True)
|
||||
def download(self, url=None, dest_old=None, *, mhtml_=False, dest=None):
|
||||
"""Download a given URL, or current page if no URL given.
|
||||
|
||||
The form `:download [url] [dest]` is deprecated, use `:download --dest
|
||||
|
@ -39,21 +39,23 @@ class ArgInfo:
|
||||
|
||||
"""Information about an argument."""
|
||||
|
||||
def __init__(self, win_id=False, count=False, flag=None):
|
||||
def __init__(self, win_id=False, count=False, flag=None, hide=False):
|
||||
if win_id and count:
|
||||
raise TypeError("Argument marked as both count/win_id!")
|
||||
self.win_id = win_id
|
||||
self.count = count
|
||||
self.flag = flag
|
||||
self.hide = hide
|
||||
|
||||
def __eq__(self, other):
|
||||
return (self.win_id == other.win_id and
|
||||
self.count == other.count and
|
||||
self.flag == other.flag)
|
||||
self.flag == other.flag and
|
||||
self.hide == other.hide)
|
||||
|
||||
def __repr__(self):
|
||||
return utils.get_repr(self, win_id=self.win_id, count=self.count,
|
||||
flag=self.flag, constructor=True)
|
||||
flag=self.flag, hide=self.hide, constructor=True)
|
||||
|
||||
|
||||
class Command:
|
||||
@ -87,7 +89,7 @@ class Command:
|
||||
"""
|
||||
|
||||
AnnotationInfo = collections.namedtuple(
|
||||
'AnnotationInfo', ['type', 'hide', 'metavar'])
|
||||
'AnnotationInfo', ['type', 'metavar'])
|
||||
|
||||
def __init__(self, *, handler, name, instance=None, maxsplit=None,
|
||||
hide=False, completion=None, modes=None, not_modes=None,
|
||||
@ -339,7 +341,7 @@ class Command:
|
||||
if typ is not bool:
|
||||
self.flags_with_args += [short_flag, long_flag]
|
||||
else:
|
||||
if not annotation_info.hide:
|
||||
if not arg_info.hide:
|
||||
self.pos_args.append((param.name, name))
|
||||
return args
|
||||
|
||||
@ -354,11 +356,11 @@ class Command:
|
||||
typ: The type to use for this argument.
|
||||
name: The long name if overridden.
|
||||
"""
|
||||
info = {'type': None, 'hide': False, 'metavar': None}
|
||||
info = {'type': None, 'metavar': None}
|
||||
if param.annotation is not inspect.Parameter.empty:
|
||||
log.commands.vdebug("Parsing annotation {}".format(
|
||||
param.annotation))
|
||||
for field in ('type', 'name', 'hide', 'metavar'):
|
||||
for field in ('type', 'name', 'metavar'):
|
||||
if field in param.annotation:
|
||||
info[field] = param.annotation[field]
|
||||
return self.AnnotationInfo(**info)
|
||||
|
@ -254,6 +254,20 @@ class TestRegister:
|
||||
expected = "fun: handler has count parameter without default!"
|
||||
assert str(excinfo.value) == expected
|
||||
|
||||
@pytest.mark.parametrize('hide', [True, False])
|
||||
def test_pos_args(self, hide):
|
||||
@cmdutils.register()
|
||||
@cmdutils.argument('arg', hide=hide)
|
||||
def fun(arg):
|
||||
"""Blah."""
|
||||
pass
|
||||
|
||||
pos_args = cmdutils.cmd_dict['fun'].pos_args
|
||||
if hide:
|
||||
assert pos_args == []
|
||||
else:
|
||||
assert pos_args == [('arg', 'arg')]
|
||||
|
||||
|
||||
class TestArgument:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user