work on v0.3.0

This commit is contained in:
2025-02-15 12:05:42 +03:00
parent ebfd5a80b3
commit 0ae86d0b2b
21 changed files with 101 additions and 36 deletions
Binary file not shown.
Binary file not shown.
+5 -2
View File
@@ -26,11 +26,14 @@ class Command:
def get_flags(self):
return self._flags
def set_command(self, command: str):
self._command = command
def validate_commands_params(self):
if not isinstance(self._command, str):
raise InvalidCommandInstanceException(self._command)
if isinstance(self._description, str):
if not isinstance(self._description, str):
raise InvalidDescriptionInstanceException()
if isinstance(self._flags, Flag) or isinstance(self._flags, FlagsGroup):
if not (isinstance(self._flags, Flag) or isinstance(self._flags, FlagsGroup)):
raise InvalidFlagsInstanceException
+8 -6
View File
@@ -11,6 +11,8 @@ class Flag:
self.possible_flag_values = possible_flag_values
self.ignore_flag_value_register = ignore_flag_value_register
self._value = None
def get_string_entity(self):
if self.ignore_flag_value_register:
string_entity: str = self.flag_prefix + self.flag_name.lower()
@@ -18,6 +20,12 @@ class Flag:
string_entity: str = self.flag_prefix + self.flag_name
return string_entity
def get_value(self):
return self._value
def set_value(self, value):
self._value = value
def validate_input_flag_value(self, input_flag_value: str):
if self.possible_flag_values:
if self.ignore_flag_value_register:
@@ -32,9 +40,3 @@ class Flag:
return False
else:
return True
c = Flag('s', flag_prefix='---kinn', ignore_flag_value_register=False, possible_flag_values=['abc', 'ASW', 'eBc'])
print(c.get_string_entity())
+4 -1
View File
@@ -1,3 +1,6 @@
from argenta.command.params.flag.entity import Flag
class FlagsGroup:
def __init__(self, flags):
def __init__(self, flags: list[Flag]):
self.flags = flags
@@ -0,0 +1,38 @@
from typing import Literal, LiteralString
from argenta.command.entity import Command
from argenta.command.params.flag.entity import Flag
from argenta.command.params.flags_group.entity import FlagsGroup
from .exceptions import InvalidInputFlagsException
class ParseInputCommand:
def __new__(cls, *args, **kwargs):
raw_command = kwargs['raw_command']
return ParseInputCommand.parse(raw_command)
@staticmethod
def parse(raw_command: str) -> Command:
list_of__ = raw_command.split()
command = list_of__[0]
list_of__.pop(0)
flags = []
for k, _ in enumerate(list_of__):
if not _.startswith('-') or len( _[:len(_.lstrip('-'))]) > 3:
raise InvalidInputFlagsException()
else:
flag_name: str = _.lstrip('-')
flag_prefix = _[:len(flag_name)]
parse_flag = Flag(flag_name=flag_name,
flag_prefix=flag_prefix)
flags.append(parse_flag)
if len(flags) == 0:
return Command(command=command)
elif len(flags) == 1:
return Command(command=command, flags=flags[0])
else:
flags = FlagsGroup(flags=flags)
return Command(command=command, flags=flags)
@@ -0,0 +1,3 @@
class InvalidInputFlagsException(Exception):
def __str__(self):
return "Invalid Input Flags"