mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
feat: impl docs (#4)
The entire public api is covered with documentation in two languages - Russian and English. the library now supports the latest three versions of python - 3.12, 3.13 and 3.14 minor design changes: now, when a Boolean flag is entered, its value is an empty string, not None. tests have been adapted to the supported versions of python, readmi has been redesigned in two languages, German is no longer available.
This commit is contained in:
@@ -1,23 +1,30 @@
|
||||
__all__ = ["PossibleValues", "ValidationStatus", "Flag", "InputFlag"]
|
||||
|
||||
from enum import Enum
|
||||
from re import Pattern
|
||||
from typing import Literal, override
|
||||
|
||||
|
||||
PREFIX_TYPE = Literal["-", "--", "---"]
|
||||
|
||||
|
||||
class PossibleValues(Enum):
|
||||
NEITHER = 'NEITHER'
|
||||
ALL = 'ALL'
|
||||
NEITHER = "NEITHER"
|
||||
ALL = "ALL"
|
||||
|
||||
|
||||
class ValidationStatus(Enum):
|
||||
VALID = 'VALID'
|
||||
INVALID = 'INVALID'
|
||||
UNDEFINED = 'UNDEFINED'
|
||||
VALID = "VALID"
|
||||
INVALID = "INVALID"
|
||||
UNDEFINED = "UNDEFINED"
|
||||
|
||||
|
||||
class Flag:
|
||||
def __init__(
|
||||
self, name: str, *,
|
||||
prefix: Literal["-", "--", "---"] = "--",
|
||||
self,
|
||||
name: str,
|
||||
*,
|
||||
prefix: PREFIX_TYPE = "--",
|
||||
possible_values: list[str] | Pattern[str] | PossibleValues = PossibleValues.ALL,
|
||||
) -> None:
|
||||
"""
|
||||
@@ -28,26 +35,29 @@ class Flag:
|
||||
:return: None
|
||||
"""
|
||||
self.name: str = name
|
||||
self.prefix: Literal["-", "--", "---"] = prefix
|
||||
self.prefix: PREFIX_TYPE = prefix
|
||||
self.possible_values: list[str] | Pattern[str] | PossibleValues = possible_values
|
||||
|
||||
def validate_input_flag_value(self, input_flag_value: str | None) -> bool:
|
||||
def validate_input_flag_value(self, input_flag_value: str) -> bool:
|
||||
"""
|
||||
Private. Validates the input flag value
|
||||
:param input_flag_value: The input flag value to validate
|
||||
:return: whether the entered flag is valid as bool
|
||||
"""
|
||||
if self.possible_values == PossibleValues.NEITHER:
|
||||
return input_flag_value is None
|
||||
return input_flag_value == ''
|
||||
|
||||
if self.possible_values == PossibleValues.ALL:
|
||||
return input_flag_value != ''
|
||||
|
||||
if isinstance(self.possible_values, Pattern):
|
||||
return isinstance(input_flag_value, str) and bool(self.possible_values.match(input_flag_value))
|
||||
return bool(self.possible_values.match(input_flag_value))
|
||||
|
||||
if isinstance(self.possible_values, list):
|
||||
return input_flag_value in self.possible_values
|
||||
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@property
|
||||
def string_entity(self) -> str:
|
||||
"""
|
||||
@@ -56,17 +66,17 @@ class Flag:
|
||||
"""
|
||||
string_entity: str = self.prefix + self.name
|
||||
return string_entity
|
||||
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return self.string_entity
|
||||
|
||||
|
||||
@override
|
||||
def __repr__(self) -> str:
|
||||
return f'Flag<name={self.name}, prefix={self.prefix}>'
|
||||
|
||||
return f"Flag<name={self.name}, prefix={self.prefix}>"
|
||||
|
||||
@override
|
||||
def __eq__(self, other: object) -> bool:
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if isinstance(other, Flag):
|
||||
return self.string_entity == other.string_entity
|
||||
else:
|
||||
@@ -75,10 +85,12 @@ class Flag:
|
||||
|
||||
class InputFlag:
|
||||
def __init__(
|
||||
self, name: str, *,
|
||||
prefix: Literal['-', '--', '---'] = '--',
|
||||
input_value: str | None,
|
||||
status: ValidationStatus | None
|
||||
self,
|
||||
name: str,
|
||||
*,
|
||||
prefix: PREFIX_TYPE = "--",
|
||||
input_value: str,
|
||||
status: ValidationStatus | None,
|
||||
):
|
||||
"""
|
||||
Public. The entity of the flag of the entered command
|
||||
@@ -88,10 +100,10 @@ class InputFlag:
|
||||
:return: None
|
||||
"""
|
||||
self.name: str = name
|
||||
self.prefix: Literal['-', '--', '---'] = prefix
|
||||
self.input_value: str | None = input_value
|
||||
self.prefix: PREFIX_TYPE = prefix
|
||||
self.input_value: str = input_value
|
||||
self.status: ValidationStatus | None = status
|
||||
|
||||
|
||||
@property
|
||||
def string_entity(self) -> str:
|
||||
"""
|
||||
@@ -103,17 +115,15 @@ class InputFlag:
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return f'{self.string_entity} {self.input_value}'
|
||||
|
||||
@override
|
||||
def __repr__(self) -> str:
|
||||
return f'InputFlag<name={self.name}, prefix={self.prefix}, value={self.input_value}, status={self.status}>'
|
||||
return f"{self.string_entity} {self.input_value}"
|
||||
|
||||
@override
|
||||
def __eq__(self, other: object) -> bool:
|
||||
def __repr__(self) -> str:
|
||||
return f"InputFlag<name={self.name}, prefix={self.prefix}, value={self.input_value}, status={self.status}>"
|
||||
|
||||
@override
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if isinstance(other, InputFlag):
|
||||
return (
|
||||
self.name == other.name
|
||||
)
|
||||
return self.name == other.name
|
||||
else:
|
||||
raise NotImplementedError
|
||||
|
||||
Reference in New Issue
Block a user