aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jesopo2020-01-27 12:13:28 +0000
committerGravatar jesopo2020-01-27 12:13:28 +0000
commit65b992e238cf2e359dec2399a444ae732f087374 (patch)
treec145a4ff2d0f978a6d2c2939824bb198e568729f
parentadd 'int' command arg spec type (diff)
signature
allow spec arguments to be "non-consuming" (doesn't show up in usage)
-rw-r--r--src/utils/parse/spec.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/utils/parse/spec.py b/src/utils/parse/spec.py
index a52dc969..17963350 100644
--- a/src/utils/parse/spec.py
+++ b/src/utils/parse/spec.py
@@ -79,6 +79,7 @@ SPEC_ARGUMENT_TYPES = {
}
class SpecArgument(object):
+ consume = True
optional: bool = False
types: typing.List[SpecArgumentType] = []
@@ -155,8 +156,15 @@ def argument_spec(spec: str) -> typing.List[SpecArgument]:
out.append(SpecLiteralArgument.parse(optional,
spec_argument[2:].split(",")))
else:
- out.append(SpecArgument.parse(optional,
- spec_argument[1:].split("|")))
+ consume = True
+ if spec_argument[1] == "=":
+ consume = False
+ spec_argument = spec_argument[1:]
+
+ spec_argument_obj = SpecArgument.parse(optional,
+ spec_argument[1:].split("|"))
+ spec_argument_obj.consume = consume
+ out.append(spec_argument_obj)
return out
@@ -164,7 +172,8 @@ def argument_spec_human(spec: typing.List[SpecArgument],
context: SpecArgumentContext=SpecArgumentContext.ALL) -> str:
arguments: typing.List[str] = []
for spec_argument in spec:
- out = spec_argument.format(context)
- if out:
- arguments.append(out)
+ if spec_argument.consume:
+ out = spec_argument.format(context)
+ if out:
+ arguments.append(out)
return " ".join(arguments)