Fix infinite loop & long flag
This commit is contained in:
parent
d2a1deb392
commit
cff82bcad6
4 changed files with 18 additions and 6 deletions
|
@ -16,3 +16,9 @@ class Flag(Option):
|
||||||
Toogle the flag
|
Toogle the flag
|
||||||
"""
|
"""
|
||||||
self.value = not self.value
|
self.value = not self.value
|
||||||
|
|
||||||
|
def long(self) -> str:
|
||||||
|
"""
|
||||||
|
Return long version of the option (--verbose, etc.)
|
||||||
|
"""
|
||||||
|
return "--{long}".format(long=self.name)
|
||||||
|
|
|
@ -35,9 +35,3 @@ class Option:
|
||||||
return self.name[0]
|
return self.name[0]
|
||||||
else:
|
else:
|
||||||
return self.single_char
|
return self.single_char
|
||||||
|
|
||||||
def long(self) -> str:
|
|
||||||
"""
|
|
||||||
Return long version of the option (--help=, --version=, etc.)
|
|
||||||
"""
|
|
||||||
return "--{long}=".format(long=self.name)
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ def parse(line: str, flags: list[Flag], values: list[Value]):
|
||||||
elements = line.split(" ")
|
elements = line.split(" ")
|
||||||
index = 0
|
index = 0
|
||||||
while index < len(elements):
|
while index < len(elements):
|
||||||
|
prev_index = index
|
||||||
element = elements[index]
|
element = elements[index]
|
||||||
logger.debug(
|
logger.debug(
|
||||||
_("parsing element {element}".format(element=element))
|
_("parsing element {element}".format(element=element))
|
||||||
|
@ -68,6 +69,11 @@ def parse(line: str, flags: list[Flag], values: list[Value]):
|
||||||
if value.long() == element[: len(value.long())]:
|
if value.long() == element[: len(value.long())]:
|
||||||
value.apply(element[len(value.long()) :])
|
value.apply(element[len(value.long()) :])
|
||||||
index += 1
|
index += 1
|
||||||
|
if index == prev_index:
|
||||||
|
logger.warning(_("unknown {element}, ignoring").format(
|
||||||
|
element = element
|
||||||
|
))
|
||||||
|
index += 1
|
||||||
except IndexError:
|
except IndexError:
|
||||||
logger.warning(_("empty value"))
|
logger.warning(_("empty value"))
|
||||||
index += 1
|
index += 1
|
||||||
|
|
|
@ -47,3 +47,9 @@ class Value(Option):
|
||||||
option=self.name,
|
option=self.name,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def long(self) -> str:
|
||||||
|
"""
|
||||||
|
Return long version of the option (--help=, --version=, etc.)
|
||||||
|
"""
|
||||||
|
return "--{long}=".format(long=self.name)
|
||||||
|
|
Loading…
Reference in a new issue