49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
from command_parser import logger
|
|
|
|
|
|
class Option:
|
|
def __init__(
|
|
self, name: str, single_char: str | None = None
|
|
) -> None:
|
|
logger.debug(_("creating new option with the name {name}"))
|
|
if single_char is None:
|
|
logger.debug(
|
|
_(
|
|
"no single char defined, first char of the option "
|
|
+ "name will be used"
|
|
)
|
|
)
|
|
else:
|
|
if len(single_char) != 1:
|
|
raise ValueError(
|
|
_(
|
|
"char representation should be only one char "
|
|
+ "long"
|
|
)
|
|
)
|
|
logger.debug(
|
|
_("single char {char} defined").format(char=single_char)
|
|
)
|
|
self.name = name
|
|
self.single_char = single_char
|
|
|
|
def one(self) -> str:
|
|
"""
|
|
Return one char form of the option (h, V, etc.)
|
|
"""
|
|
if self.single_char is None:
|
|
return self.name[0]
|
|
else:
|
|
return self.single_char
|
|
|
|
def short(self) -> str:
|
|
"""
|
|
Return short version of the option (-h, -V, etc.)
|
|
"""
|
|
return "-{one}".format(one=self.one())
|
|
|
|
def long(self) -> str:
|
|
"""
|
|
Return long version of the option (--help=, --version=, etc.)
|
|
"""
|
|
return "--{long}=".format(long=self.name)
|