Update formating
This commit is contained in:
parent
8fdb78b908
commit
94edd899d0
4 changed files with 20 additions and 14 deletions
|
@ -1,7 +1,13 @@
|
||||||
from command_parser.option import Option
|
from command_parser.option import Option
|
||||||
|
|
||||||
|
|
||||||
class Flag(Option):
|
class Flag(Option):
|
||||||
def __init__(self, name: str, default: bool = False, single_char: str | None = None) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
default: bool = False,
|
||||||
|
single_char: str | None = None,
|
||||||
|
) -> None:
|
||||||
super(Flag, self).__init__(name, single_char)
|
super(Flag, self).__init__(name, single_char)
|
||||||
self.value = default
|
self.value = default
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
from command_parser import logger
|
from command_parser import logger
|
||||||
|
|
||||||
|
|
||||||
class Option:
|
class Option:
|
||||||
def __init__(self, name: str, single_char: str | None = None) -> None:
|
def __init__(
|
||||||
logger.debug(
|
self, name: str, single_char: str | None = None
|
||||||
_("creating new option with the name {name}")
|
) -> None:
|
||||||
)
|
logger.debug(_("creating new option with the name {name}"))
|
||||||
if single_char is None:
|
if single_char is None:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
_(
|
_(
|
||||||
|
@ -21,9 +22,7 @@ class Option:
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
_(
|
_("single char {char} defined").format(char=single_char)
|
||||||
"single char {char} defined"
|
|
||||||
).format(char = single_char)
|
|
||||||
)
|
)
|
||||||
self.name = name
|
self.name = name
|
||||||
self.single_char = single_char
|
self.single_char = single_char
|
||||||
|
|
|
@ -3,6 +3,7 @@ from command_parser import logger
|
||||||
from command_parser.flag import Flag
|
from command_parser.flag import Flag
|
||||||
from command_parser.value import Value
|
from command_parser.value import Value
|
||||||
|
|
||||||
|
|
||||||
def parse(line: str, flags: list[Flag], values: list[Value]):
|
def parse(line: str, flags: list[Flag], values: list[Value]):
|
||||||
"""
|
"""
|
||||||
parse a command line parser
|
parse a command line parser
|
||||||
|
@ -46,7 +47,7 @@ def parse(line: str, flags: list[Flag], values: list[Value]):
|
||||||
index += 1
|
index += 1
|
||||||
for value in values:
|
for value in values:
|
||||||
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
|
||||||
except IndexError:
|
except IndexError:
|
||||||
logger.warning(_("empty value"))
|
logger.warning(_("empty value"))
|
||||||
|
|
|
@ -15,14 +15,14 @@ class Value(Option):
|
||||||
if allowlist is None:
|
if allowlist is None:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
_("every values is accepted for {option}").format(
|
_("every values is accepted for {option}").format(
|
||||||
option = self.name,
|
option=self.name,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
_(
|
_(
|
||||||
"only some values is accepted for {option}".format(
|
"only some values is accepted for {option}".format(
|
||||||
option = self.name
|
option=self.name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -43,7 +43,7 @@ class Value(Option):
|
||||||
"{value} is not an accepted value for the "
|
"{value} is not an accepted value for the "
|
||||||
+ "option {option}"
|
+ "option {option}"
|
||||||
).format(
|
).format(
|
||||||
value = value,
|
value=value,
|
||||||
option = self.name,
|
option=self.name,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue