Fix Signature for Greedy/Optional converters
Change Greedy to `[a]...` | `[a=1]...`
This commit is contained in:
parent
c960465366
commit
63c5892b43
@ -795,11 +795,23 @@ class Command(_BaseCommand):
|
|||||||
return self.help.split('\n', 1)[0]
|
return self.help.split('\n', 1)[0]
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
def _is_typing_optional(self, annotation):
|
||||||
|
try:
|
||||||
|
origin = annotation.__origin__
|
||||||
|
except AttributeError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if origin is not typing.Union:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return annotation.__args__[-1] is type(None)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def signature(self):
|
def signature(self):
|
||||||
"""Returns a POSIX-like signature useful for help command output."""
|
"""Returns a POSIX-like signature useful for help command output."""
|
||||||
result = []
|
result = []
|
||||||
parent = self.full_parent_name
|
parent = self.full_parent_name
|
||||||
|
|
||||||
if len(self.aliases) > 0:
|
if len(self.aliases) > 0:
|
||||||
aliases = '|'.join(self.aliases)
|
aliases = '|'.join(self.aliases)
|
||||||
fmt = '[%s|%s]' % (self.name, aliases)
|
fmt = '[%s|%s]' % (self.name, aliases)
|
||||||
@ -819,16 +831,25 @@ class Command(_BaseCommand):
|
|||||||
return ' '.join(result)
|
return ' '.join(result)
|
||||||
|
|
||||||
for name, param in params.items():
|
for name, param in params.items():
|
||||||
|
greedy = isinstance(param.annotation, converters._Greedy)
|
||||||
|
|
||||||
if param.default is not param.empty:
|
if param.default is not param.empty:
|
||||||
# We don't want None or '' to trigger the [name=value] case and instead it should
|
# We don't want None or '' to trigger the [name=value] case and instead it should
|
||||||
# do [name] since [name=None] or [name=] are not exactly useful for the user.
|
# do [name] since [name=None] or [name=] are not exactly useful for the user.
|
||||||
should_print = param.default if isinstance(param.default, str) else param.default is not None
|
should_print = param.default if isinstance(param.default, str) else param.default is not None
|
||||||
if should_print:
|
if should_print:
|
||||||
result.append('[%s=%s]' % (name, param.default))
|
result.append('[%s=%s]' % (name, param.default) if not greedy else
|
||||||
|
'[%s=%s]...' % (name, param.default))
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
result.append('[%s]' % name)
|
result.append('[%s]' % name)
|
||||||
|
|
||||||
elif param.kind == param.VAR_POSITIONAL:
|
elif param.kind == param.VAR_POSITIONAL:
|
||||||
result.append('[%s...]' % name)
|
result.append('[%s...]' % name)
|
||||||
|
elif greedy:
|
||||||
|
result.append('[%s]...' % name)
|
||||||
|
elif self._is_typing_optional(param.annotation):
|
||||||
|
result.append('[%s]' % name)
|
||||||
else:
|
else:
|
||||||
result.append('<%s>' % name)
|
result.append('<%s>' % name)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user