add a flag command spec type

This commit is contained in:
jesopo 2020-03-05 10:41:05 +00:00
parent e8388a28bd
commit 1c09f7c854

View file

@ -15,6 +15,7 @@ class SpecArgumentContext(enum.IntFlag):
class SpecArgumentType(object): class SpecArgumentType(object):
context = SpecArgumentContext.ALL context = SpecArgumentContext.ALL
_modifier: typing.Optional[str]
def __init__(self, type_name: str, name: typing.Optional[str], def __init__(self, type_name: str, name: typing.Optional[str],
modifier: typing.Optional[str], exported: typing.Optional[str]): modifier: typing.Optional[str], exported: typing.Optional[str]):
@ -24,7 +25,7 @@ class SpecArgumentType(object):
self.exported = exported self.exported = exported
def _set_modifier(self, modifier: typing.Optional[str]): def _set_modifier(self, modifier: typing.Optional[str]):
pass self._modifier = modifier
def name(self) -> typing.Optional[str]: def name(self) -> typing.Optional[str]:
return self._name return self._name
@ -102,6 +103,18 @@ class SpecArgumentTypeDate(SpecArgumentType):
return date_human(args[0]), 1 return date_human(args[0]), 1
return None, 1 return None, 1
class SpecArgumentTypeFlag(SpecArgumentType):
def _str(self):
pref = "-" if len(self._modifier) == 1 else "--"
return f"{pref}{self._modifier}"
def name(self):
return self._str()
def simple(self, args):
print("flag _str()", self._str())
if args and args[0] == self._str():
return True, 1
return None, 1
class SpecArgumentPrivateType(SpecArgumentType): class SpecArgumentPrivateType(SpecArgumentType):
context = SpecArgumentContext.PRIVATE context = SpecArgumentContext.PRIVATE
@ -115,7 +128,8 @@ SPEC_ARGUMENT_TYPES = {
"int": SpecArgumentTypeInt, "int": SpecArgumentTypeInt,
"date": SpecArgumentTypeDate, "date": SpecArgumentTypeDate,
"duration": SpecArgumentTypeDuration, "duration": SpecArgumentTypeDuration,
"pattern": SpecArgumentTypePattern "pattern": SpecArgumentTypePattern,
"flag": SpecArgumentTypeFlag
} }
class SpecArgument(object): class SpecArgument(object):