work on v0.3.0

This commit is contained in:
2025-02-17 20:57:15 +03:00
parent 37b62fd69b
commit a9e545f3d8
20 changed files with 47 additions and 77 deletions
+3 -3
View File
@@ -1,8 +1,8 @@
from typing import Callable
from ..command.entity import Command
from argenta.command.parse_input_command.entity import ParseInputCommand
from argenta.command.input_comand.entity import InputCommand
from argenta.command.input_comand.exceptions import InvalidInputFlagsException
from ..router.entity import Router
from ..command.parse_input_command.exceptions import InvalidInputFlagsException
from .exceptions import (InvalidRouterInstanceException,
InvalidDescriptionMessagePatternException,
OnlyOneMainRouterIsAllowedException,
@@ -68,7 +68,7 @@ class App:
raw_command: str = input()
try:
command: Command = ParseInputCommand(raw_command=raw_command)
command: Command = InputCommand.parse(raw_command=raw_command)
except InvalidInputFlagsException:
self.print_func(self.line_separate)
self.print_func(self.command_group_description_separate)
Binary file not shown.
Binary file not shown.
+2 -1
View File
@@ -13,6 +13,8 @@ class Command:
self._description = description
self._flags = flags
self._input_flags = None
def get_string_entity(self):
return self._command
@@ -30,7 +32,6 @@ class Command:
self._command = command
def validate_commands_params(self):
print(self._flags)
if not isinstance(self._command, str):
raise InvalidCommandInstanceException(self._command)
if not isinstance(self._description, str):
@@ -1,19 +1,20 @@
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
from argenta.command.input_comand.exceptions import InvalidInputFlagsException
from ..entity import Command
from ..params.flags_group.entity import FlagsGroup
from ..params.input_flag.entity import InputFlag
class ParseInputCommand:
def __new__(cls, *args, **kwargs):
raw_command = kwargs['raw_command']
return ParseInputCommand.parse(raw_command)
class InputCommand(Command):
def set_input_flags(self, input_flags: list[InputFlag]):
self._input_flags = input_flags
def get_input_flags(self) -> list[InputFlag]:
return self._input_flags
@staticmethod
def parse(raw_command: str) -> Command:
list_of_tokens = raw_command.split()
command_name = list_of_tokens[0]
command = list_of_tokens[0]
list_of_tokens.pop(0)
flags = []
@@ -23,33 +24,31 @@ class ParseInputCommand:
flag_prefix_last_symbol_index = _.rfind('-')
if _.startswith('-'):
if current_flag_name or len(_) < 2 or len(_[:flag_prefix_last_symbol_index]) > 3:
raise
raise InvalidInputFlagsException
else:
current_flag_name = _
else:
if not current_flag_name:
raise
raise InvalidInputFlagsException
else:
current_flag_value = _
if current_flag_name and current_flag_value:
flag_prefix = _[:flag_prefix_last_symbol_index]
flag_name = _[flag_prefix_last_symbol_index:]
flags.append(Flag(flag_name=flag_name, flag_prefix=flag_prefix))
input_flag = InputFlag(flag_name=flag_name,
flag_prefix=flag_prefix)
input_flag.set_value(current_flag_value)
flags.append(input_flag)
current_flag_name = None
current_flag_value = None
command = Command(command_name, flags)
return command
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,11 @@
from ...params.flag.entity import Flag
class InputFlag(Flag):
def set_value(self, value: str):
self._value = value
def get_value(self) -> str:
return self._value