mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
work on stable major version
This commit is contained in:
+20
-3
@@ -1,6 +1,23 @@
|
|||||||
|
from argenta.response import Response, Status
|
||||||
from argenta.app import App
|
from argenta.app import App
|
||||||
|
from argenta.app.dividing_line import StaticDividingLine, DynamicDividingLine
|
||||||
|
from argenta.app.autocompleter import AutoCompleter
|
||||||
|
from argenta.app.defaults import PredefinedMessages
|
||||||
|
from argenta.command import Command
|
||||||
|
from argenta.command.flags import Flags, InputFlags, InvalidValueInputFlags, UndefinedInputFlags, ValidInputFlags
|
||||||
|
from argenta.command.flag import Flag, InputFlag
|
||||||
|
from argenta.command.flag.defaults import PredefinedFlags
|
||||||
|
from argenta.router import Router
|
||||||
|
from argenta.orchestrator import Orchestrator
|
||||||
|
|
||||||
from argenta.command.models import InputCommand
|
from argenta.command.models import InputCommand
|
||||||
|
|
||||||
app = App()
|
|
||||||
app._all_registered_triggers_in_lower = ['fr', 'Tre', 'Pre']
|
while True:
|
||||||
print(app._is_unknown_command(InputCommand('fr')))
|
cmd = input(">>> ")
|
||||||
|
if cmd == "exit":
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
parse_cmd: InputCommand = InputCommand.parse(cmd)
|
||||||
|
print(f'name: {parse_cmd.get_trigger()}\n'
|
||||||
|
f'flags: {parse_cmd.get_input_flags().get_flags()}\n')
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ def command_help(response: Response):
|
|||||||
@work_router.command(Command('run', 'Run All'))
|
@work_router.command(Command('run', 'Run All'))
|
||||||
def command_start_solving(response: Response):
|
def command_start_solving(response: Response):
|
||||||
print(response.status)
|
print(response.status)
|
||||||
print('srsfbd')
|
|
||||||
print(response.undefined_flags.get_flags())
|
print(response.undefined_flags.get_flags())
|
||||||
print(response.valid_flags.get_flags())
|
print(response.valid_flags.get_flags())
|
||||||
print(response.invalid_value_flags.get_flags())
|
print(response.invalid_value_flags.get_flags())
|
||||||
|
|||||||
@@ -1 +1,4 @@
|
|||||||
|
__all__ = ["Flag", "InputFlag"]
|
||||||
|
|
||||||
|
|
||||||
|
from argenta.command.flag.models import Flag, InputFlag
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
__all__ = ["Flags", "InputFlags",
|
||||||
|
"UndefinedInputFlags",
|
||||||
|
"InvalidValueInputFlags",
|
||||||
|
"ValidInputFlags"]
|
||||||
|
|
||||||
|
|
||||||
|
from argenta.command.flags.models import (Flags, InputFlags,
|
||||||
|
UndefinedInputFlags,
|
||||||
|
InvalidValueInputFlags,
|
||||||
|
ValidInputFlags)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
__all__ = ["Response", "Status"]
|
||||||
|
|
||||||
|
|
||||||
from argenta.response.entity import Response
|
from argenta.response.entity import Response
|
||||||
from argenta.response.status import Status
|
from argenta.response.status import Status
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['Response', 'Status']
|
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ from enum import Enum
|
|||||||
|
|
||||||
|
|
||||||
class Status(Enum):
|
class Status(Enum):
|
||||||
SUCCESSFUL = 200
|
ALL_FLAGS_VALID = 'ALL_FLAGS_VALID'
|
||||||
partSUCCESSFUL = 206
|
UNDEFINED_FLAGS = 'UNDEFINED_FLAGS'
|
||||||
UNSUCCESSFUL = 400
|
INVALID_VALUE_FLAGS = 'INVALID_VALUE_FLAGS'
|
||||||
|
UNDEFINED_AND_INVALID_FLAGS = 'UNDEFINED_AND_INVALID_FLAGS'
|
||||||
|
|
||||||
|
|||||||
@@ -72,28 +72,29 @@ class Router:
|
|||||||
response: Response = Response()
|
response: Response = Response()
|
||||||
if handle_command.get_registered_flags().get_flags():
|
if handle_command.get_registered_flags().get_flags():
|
||||||
if input_command_flags.get_flags():
|
if input_command_flags.get_flags():
|
||||||
response.status = Status.SUCCESSFUL
|
flags, status = self._validate_input_flags(handle_command, input_command_flags)
|
||||||
flags = self._validate_input_flags(handle_command, input_command_flags)
|
|
||||||
response.valid_flags, response.undefined_flags, response.invalid_value_flags = flags
|
response.valid_flags, response.undefined_flags, response.invalid_value_flags = flags
|
||||||
|
response.status = status
|
||||||
command_handler.handling(response)
|
command_handler.handling(response)
|
||||||
else:
|
else:
|
||||||
response.status = Status.SUCCESSFUL
|
response.status = Status.ALL_FLAGS_VALID
|
||||||
command_handler.handling(response)
|
command_handler.handling(response)
|
||||||
else:
|
else:
|
||||||
if input_command_flags.get_flags():
|
if input_command_flags.get_flags():
|
||||||
response.status = Status.UNSUCCESSFUL
|
response.status = Status.UNDEFINED_FLAGS
|
||||||
response.undefined_flags = UndefinedInputFlags()
|
response.undefined_flags = UndefinedInputFlags()
|
||||||
response.undefined_flags.add_flags(input_command_flags.get_flags())
|
response.undefined_flags.add_flags(input_command_flags.get_flags())
|
||||||
command_handler.handling(response)
|
command_handler.handling(response)
|
||||||
else:
|
else:
|
||||||
response.status = Status.SUCCESSFUL
|
response.status = Status.ALL_FLAGS_VALID
|
||||||
command_handler.handling(response)
|
command_handler.handling(response)
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _validate_input_flags(handled_command: Command, input_flags: InputFlags) -> tuple[ValidInputFlags,
|
def _validate_input_flags(handled_command: Command, input_flags: InputFlags) -> tuple[tuple[ValidInputFlags,
|
||||||
UndefinedInputFlags,
|
UndefinedInputFlags,
|
||||||
InvalidValueInputFlags]:
|
InvalidValueInputFlags],
|
||||||
|
Status]:
|
||||||
"""
|
"""
|
||||||
Private. Validates flags of input command
|
Private. Validates flags of input command
|
||||||
:param handled_command: entity of the handled command
|
:param handled_command: entity of the handled command
|
||||||
@@ -112,7 +113,17 @@ class Router:
|
|||||||
undefined_input_flags.add_flag(flag)
|
undefined_input_flags.add_flag(flag)
|
||||||
case 'Invalid':
|
case 'Invalid':
|
||||||
invalid_value_input_flags.add_flag(flag)
|
invalid_value_input_flags.add_flag(flag)
|
||||||
return valid_input_flags, undefined_input_flags, invalid_value_input_flags
|
|
||||||
|
if not invalid_value_input_flags.get_flags() and not undefined_input_flags.get_flags():
|
||||||
|
status = Status.ALL_FLAGS_VALID
|
||||||
|
elif invalid_value_input_flags.get_flags() and not undefined_input_flags.get_flags():
|
||||||
|
status = Status.INVALID_VALUE_FLAGS
|
||||||
|
elif not invalid_value_input_flags.get_flags() and undefined_input_flags.get_flags():
|
||||||
|
status = Status.UNDEFINED_FLAGS
|
||||||
|
else:
|
||||||
|
status = Status.UNDEFINED_AND_INVALID_FLAGS
|
||||||
|
|
||||||
|
return (valid_input_flags, undefined_input_flags, invalid_value_input_flags), status
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user