mh CmdMixin - added ArgFormat.BOOLEAN_NOT and logic (#3290)

* mh CmdMixin - added ArgFormat.BOOLEAN_NOT and logic

* added changelog fragment
This commit is contained in:
Alexei Znamensky 2021-08-29 23:03:15 +12:00 committed by GitHub
commit df8fdcda79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 3 deletions

View file

@ -16,6 +16,7 @@ class ArgFormat(object):
BOOLEAN = 0
PRINTF = 1
FORMAT = 2
BOOLEAN_NOT = 3
@staticmethod
def stars_deco(num):
@ -50,12 +51,14 @@ class ArgFormat(object):
_fmts = {
ArgFormat.BOOLEAN: lambda _fmt, v: ([_fmt] if bool(v) else []),
ArgFormat.BOOLEAN_NOT: lambda _fmt, v: ([] if bool(v) else [_fmt]),
ArgFormat.PRINTF: printf_fmt,
ArgFormat.FORMAT: lambda _fmt, v: [_fmt.format(v)],
}
self.name = name
self.stars = stars
self.style = style
if fmt is None:
fmt = "{0}"
@ -76,7 +79,7 @@ class ArgFormat(object):
self.arg_format = (self.stars_deco(stars))(self.arg_format)
def to_text(self, value):
if value is None:
if value is None and self.style != ArgFormat.BOOLEAN_NOT:
return []
func = self.arg_format
return [str(p) for p in func(value)]