diff options
| author | 2020-01-25 22:56:56 +0000 | |
|---|---|---|
| committer | 2020-01-25 22:56:56 +0000 | |
| commit | 0c28d638225c9212324c0772d9de8912eb028fae (patch) | |
| tree | 462f9b7c89968bb54d4f3ff111a73f33e7d2c0f1 | |
| parent | implement default spec argument types (diff) | |
| signature | ||
add utils.parse.argument_spec_human() for usage strings
| -rw-r--r-- | src/utils/parse.py | 13 |
1 files changed, 13 insertions, 0 deletions
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) |
