From 0c28d638225c9212324c0772d9de8912eb028fae Mon Sep 17 00:00:00 2001 From: jesopo Date: Sat, 25 Jan 2020 22:56:56 +0000 Subject: [PATCH] add utils.parse.argument_spec_human() for usage strings --- src/utils/parse.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/utils/parse.py b/src/utils/parse.py index 3af092f1..d2198e5f 100644 --- a/src/utils/parse.py +++ b/src/utils/parse.py @@ -232,3 +232,16 @@ def argument_spec(spec: str) -> typing.List[SpecArgument]: argument_type_name, exported)) out.append(SpecArgument(optional, argument_types)) return out + +def argument_spec_human(spec: typing.List[SpecArgument]) -> str: + out: typing.List[str] = [] + for spec_argument in spec: + names = [t.name() or t.type for t in spec_argument.types] + names = list(filter(None, names)) + + if spec_argument.optional: + format = "[%s]" + else: + format = "<%s>" + out.append(format % "|".join(names)) + return " ".join(out)