From a9e545f3d8fe60ff81049837097c7c1e49024b5d Mon Sep 17 00:00:00 2001 From: kolo Date: Mon, 17 Feb 2025 20:57:15 +0300 Subject: [PATCH] work on v0.3.0 --- .gitignore | 6 ++ argenta/app/entity.py | 6 +- .../__pycache__/__init__.cpython-313.pyc | Bin 163 -> 0 bytes .../__pycache__/entity.cpython-313.pyc | Bin 2533 -> 0 bytes .../__pycache__/exceptions.cpython-313.pyc | Bin 1278 -> 0 bytes argenta/command/entity.py | 3 +- .../__init__.py | 0 .../entity.py | 41 ++++++------- .../exceptions.py | 0 .../__pycache__/__init__.cpython-313.pyc | Bin 170 -> 0 bytes .../flag/__pycache__/__init__.cpython-313.pyc | Bin 175 -> 0 bytes .../flag/__pycache__/entity.cpython-313.pyc | Bin 2172 -> 0 bytes .../__pycache__/__init__.cpython-313.pyc | Bin 182 -> 0 bytes .../__pycache__/entity.cpython-313.pyc | Bin 664 -> 0 bytes argenta/command/params/input_flag/__init__.py | 0 argenta/command/params/input_flag/entity.py | 11 ++++ .../__pycache__/__init__.cpython-313.pyc | Bin 183 -> 0 bytes .../__pycache__/entity.cpython-313.pyc | Bin 2166 -> 0 bytes .../__pycache__/exceptions.cpython-313.pyc | Bin 601 -> 0 bytes tests/test.py | 57 ++---------------- 20 files changed, 47 insertions(+), 77 deletions(-) delete mode 100644 argenta/command/__pycache__/__init__.cpython-313.pyc delete mode 100644 argenta/command/__pycache__/entity.cpython-313.pyc delete mode 100644 argenta/command/__pycache__/exceptions.cpython-313.pyc rename argenta/command/{parse_input_command => input_comand}/__init__.py (100%) rename argenta/command/{parse_input_command => input_comand}/entity.py (58%) rename argenta/command/{parse_input_command => input_comand}/exceptions.py (100%) delete mode 100644 argenta/command/params/__pycache__/__init__.cpython-313.pyc delete mode 100644 argenta/command/params/flag/__pycache__/__init__.cpython-313.pyc delete mode 100644 argenta/command/params/flag/__pycache__/entity.cpython-313.pyc delete mode 100644 argenta/command/params/flags_group/__pycache__/__init__.cpython-313.pyc delete mode 100644 argenta/command/params/flags_group/__pycache__/entity.cpython-313.pyc create mode 100644 argenta/command/params/input_flag/__init__.py create mode 100644 argenta/command/params/input_flag/entity.py delete mode 100644 argenta/command/parse_input_command/__pycache__/__init__.cpython-313.pyc delete mode 100644 argenta/command/parse_input_command/__pycache__/entity.cpython-313.pyc delete mode 100644 argenta/command/parse_input_command/__pycache__/exceptions.cpython-313.pyc diff --git a/.gitignore b/.gitignore index 48c0136..3e452dd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,11 @@ argenta/router/__pycache__/ argenta/app/__pycache__/ argenta/__pycache__/ +argenta/command/__pycache__ +argenta/command/params/__pycache__ +argenta/command/params/flag/__pycache__ +argenta/command/params/flags_group/__pycache__ +argenta/command/params/input_flag/__pycache__ dist poetry.lock tests/__pycache__ @@ -13,3 +18,4 @@ tests/mock_app/handlers/handlers_implementation/__pycache__/ tests/mock_app/handlers/__pycache__/ tests/mock_app/business_logic/__pycache__/ tests/mock_app/__pycache__/ + diff --git a/argenta/app/entity.py b/argenta/app/entity.py index 6e42047..d31447b 100644 --- a/argenta/app/entity.py +++ b/argenta/app/entity.py @@ -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) diff --git a/argenta/command/__pycache__/__init__.cpython-313.pyc b/argenta/command/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index 7a8b8f9e9277823045d251b24f9a5ce27320f57c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 163 zcmey&%ge<81aH4?NC(l6K?DpiLK&Y~fQ+dO=?t2Tek&P@n1H;`AgNnU&Q>v@#i>Qb zG1>V!`I#{Rl_eSZdGP^7`B|ySCB-q0Md_(|C5bVKP&zq3H#adaB_=*TGcU6wK3=b& h@)n0pZhlH>PO4oIE6_-gmBk>&M`lJw#v*1Q3jpgbD)0aR diff --git a/argenta/command/__pycache__/entity.cpython-313.pyc b/argenta/command/__pycache__/entity.cpython-313.pyc deleted file mode 100644 index e8c89ad045d283f6cf8f27bb2fb428fcf7c7dd23..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2533 zcmb7GO=ufe5PqxGO0s?;TWS(naqO+D(5goMY2v1BN=b>EVjE285-^cqyOGxFI?~F0 zyDm*aAcs;ZCbWwmi3RmEbB|Q(JW93F8yTZemudxte^C1uea{Kx1$MjU!6{ zvrxMX#7>`iuXNthsa3kvs5Okzxy$xv4O2Zw8;g3`wn`t;s&3j^Npo9QTL}gY`|{}0 zWw1asOv6@H*6X@I>W%cEs#kzrCz~PCFMpfp47~m@(%(6B)w!SgNLD$|3&SzlGRRm-M^Syde?S-)pk*HkZVMp&+sPBMM_ z+Rbat$N+AJ<>aWwy?AaT$o%CQcKKM9&xSh_m(z#|l*NxKuiC?Y`*spxHci zS)bovK7@JUi`LbfSDTTnV}~DWlzFr;x;w8^)yW=;Cwb7})z|@D%mN!+tXbN#!Z&yn zcR=Yt$TCB>65UV)VUnBh4fwV~is&Jyz0+dSotH@w>h<=@kSD)vi(YjjUJc$(JIMYb z`oanH?6KR^qYFFq;04%4|DgxomLgt3PLpoC>qLJz+!aNP2B$8|hu}oN-+S%GjNf}V z6tuljy$A>t@pf?11vmKl7?YNuJlH$~S=6u$_f6tAiiuD>D4OHkGK7(0EGY(+V%WQ~ zHp5>y&DOoNvD77vYITdrUi$2}LWc9KuYg@A8xvOa=#RQEIde^ZpKgZ`F3`sl^waSw38F9&j*g#A9m4q%m%)siERwjRMs+Adkj*Ffh5Tv8eLXvb0r6ZdmL6Ywt|A#>H zJQSA39d)Q_F5kmaPV`2x>Wn&%2zQ9}`z9>4ik~>%JZ1-r>fUFK<)jeL9-cGYi??9W vOV3#3eFxJI=-V)XMZiLgHbp@Y9+BK5GVvl15Z-x8fW3$g3FFTQFn++l&88CD diff --git a/argenta/command/__pycache__/exceptions.cpython-313.pyc b/argenta/command/__pycache__/exceptions.cpython-313.pyc deleted file mode 100644 index b333e715159074de690d4e676eca5bc6cb2b624a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1278 zcmbVL&u`N(6ta^+F(ZhV4#_6DR(I z-gl%o{v4DmCk{wRY47;iaS0&NX+Au^yyy4%`TJg~UayPP`my+uGK|nS_^_*0JJpeL zrf3`8Lm}EhA&$^v*W@_XQAb7HM%2+!PeogesGGL^PGZqvS2yZa?Wk>vBE)fsxD#UT zh6&=>C$dMdMmeFvz-;sGf5&}HQ*Ges%( zo#BV=8m3?4^exZ~&2Z@nnx6;zt>ulU~ZO^y1R;`o9Z+N15Gzb+B1ca8Twwiz8nWLjhb6s`{%5dYfsG&@QmM4 mrFvj}<@|Ip#&gHP`xn_9scqhMaPZj&KLCI4Vz5xYx%L;^LL{*O diff --git a/argenta/command/entity.py b/argenta/command/entity.py index 93c17ae..e457a54 100644 --- a/argenta/command/entity.py +++ b/argenta/command/entity.py @@ -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): diff --git a/argenta/command/parse_input_command/__init__.py b/argenta/command/input_comand/__init__.py similarity index 100% rename from argenta/command/parse_input_command/__init__.py rename to argenta/command/input_comand/__init__.py diff --git a/argenta/command/parse_input_command/entity.py b/argenta/command/input_comand/entity.py similarity index 58% rename from argenta/command/parse_input_command/entity.py rename to argenta/command/input_comand/entity.py index d54000c..4d2ed93 100644 --- a/argenta/command/parse_input_command/entity.py +++ b/argenta/command/input_comand/entity.py @@ -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) + + diff --git a/argenta/command/parse_input_command/exceptions.py b/argenta/command/input_comand/exceptions.py similarity index 100% rename from argenta/command/parse_input_command/exceptions.py rename to argenta/command/input_comand/exceptions.py diff --git a/argenta/command/params/__pycache__/__init__.cpython-313.pyc b/argenta/command/params/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index e7facaa87f7772a1a259445a3d2ce3e718a7a2fa..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 170 zcmey&%ge<81aH4?NC(l6K?DpiLK&Y~fQ+dO=?t2Tek&P@n1H;`AgNoP&Q>v@#i>Qb zG1>V!`I#{Rl_eSZdGP^7`B|ySCB-q0Md_(|C5bVKP&zq3H#adaC8i*;C^5Gv@#i>Qb zG1>V!`I#{Rl_eSZdGP^7`B|ySCB-q0Md_(|C5bVKP&zq3H#adaC8i*;C^5GPO4oIE6{k5^~E5@M`lJw#v*1Q3jl9HFVX-2 diff --git a/argenta/command/params/flag/__pycache__/entity.cpython-313.pyc b/argenta/command/params/flag/__pycache__/entity.cpython-313.pyc deleted file mode 100644 index 0d607b6cf1ca0438c7d130fd542751829d221b72..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2172 zcmb7F&2JM&6o0ec^+z1Xp@xt;5bVSxEUgo0O-pI10znZHAlzV$CRS$3hj_rSd8zfsRRf^OThgNPPgnH|nS=(_^QmGT?&3p6S%)Iw| zZ{BXDQeA-Kj~5T@9~FS#xzHMNli4aDvj!Sy zoNyR}s3Ck)l|W{eyU=07)xwZ*$8vlGGm~fZtIVQI|IBkeN58!4f9h3?%hX%6%0AQ2 zQQNBcrfxRpvbVHkR_66(lbTCR=UC`y;P|U!%d0`$Fr13x8%B_tLd{r9?lg_Y*Q}h{F|}caLMu z1ycoX(Z+Dw4p-awZLeP85bheMnsO263b{%O|Lerlj&OWIR5JSqqY3WYX0Pd z3y)_X&elp7tEG$UrRi#Z`tGGh6nYOojUQ@6U}&V%teQW6_fkE52z4}r2kyuO&x*)I z7MZ;=Q2-J5eL{QCN+lvp#*fKT$Ln z{``r|Ua+(a)Yz*)+ZJchf?Vlr9(XPvt-^fu6Ue|diAm$Yq>HZsctihn!e!~wet;z8 z(7GbMk7t{hA)DCJT<@!%SEq$dm=x|?05vlE@st|bZa?$@o`nm%wrL(oKyES)4mO*x zs$a)+IP<1&VXN2)YA`6uVNd;GJcgM_npIw?B@0+5we%SN>Y3qMMy+Pl^~@VTmui#x zuao-v`1R_f{=|G7dl-9^K(;!5eLZu%K5%4XAh&@VMklJH6YH6Y*2=-ZHxIyxPYB~F z{RR5Zy%ohS%j@`6ZFCmnOrUORO6}pTkAFb0^>rD>k~hDC-vT4(HjK|#Ot+~?8^(e| zneRFktKy+Lg0Gu$bOQN?=edFG;^&0!=p6zKo8L{!Kt4_WT3->cVaS diff --git a/argenta/command/params/flags_group/__pycache__/__init__.cpython-313.pyc b/argenta/command/params/flags_group/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index 6c90035e6fd04d5a864e1c90d005bfb030e7898d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 182 zcmey&%ge<81aH4?NC(l6K?DpiLK&Y~fQ+dO=?t2Tek&P@n1H;`AgNoS&Q>v@#i>Qb zG1>V!`I#{Rl_eSZdGP^7`B|ySCB-q0Md_(|C5bVKP&zq3H#adaC8i*;C^5G>v28MBOZ{2f0&Np+#b*b#^ zJkZWIoqvuDSXreIf{Ube-tI;R<~P6h{hQb9?Tx^lUw^)3pWOSCjH?s$q`BwF7C3PB z5?(N5Q@9ImX7D{<=I>^s=P>;0m26J$=!?2O@# zw%5?%#(E@E%-*WH)E<6?&oJGDp>~|3NJBYg-#I%FB`+O&% nZ9S&`|Hj$jarc+Uc*g~pyY0*ipE33W9$XGQcJLb str: + return self._value + + diff --git a/argenta/command/parse_input_command/__pycache__/__init__.cpython-313.pyc b/argenta/command/parse_input_command/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index 3ae01c01ee19263f824df7c69c6b037f3050ae09..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 183 zcmey&%ge<81aH4?NC(l6K?DpiLK&Y~fQ+dO=?t2Tek&P@n1H;`AgNnn&Q>v@#i>Qb zG1>V!`I#{Rl_eSZdGP^7`B|ySCB-q0Md_(|C5bVKP&zq3H#adaC8i*;s5mt~Gq0eu uBpxOf59DW-#K-FuRNmsS$<0qG%}KQ@Vg*_Qaz-(T@sXL4k+Fyw$N~UJ^fO2R diff --git a/argenta/command/parse_input_command/__pycache__/entity.cpython-313.pyc b/argenta/command/parse_input_command/__pycache__/entity.cpython-313.pyc deleted file mode 100644 index 51b6d51c45145aa9e2dd4334231ceae803ac3bc9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2166 zcmaJ?&2JM&6rcU{`m0W`=1mz(u`wW_CA(fOyi*yqS3)^WOW- z+jcx20hs=Iey@010N`)32#EKY_65w`0t!%=aWKX}W{ibwmaN%vZj6UK<+*WTOoSrk z`SH-01SQN1iZ~t~i@-=0bc3Bh3H1O)I?Q^OVYC>QBdcT~vnceb=^9Wkp}5Z|E;Oy8 z%%ISzO1Z3C)0pKyF6m?|LT2X^SgG2p4AEy$&spnhy<|?Gwd|@(kI!5y7`AIxtb*sy z8*!MF+8^NQ7RUq0C;+kw138850g%rN3YQlZJ|8;7D?$&r%pdkuprnW}Tnxz)>O8MQ z$DqFa+pS7isz5Fi5Qmur{(Mg=_CcIm+*BX|CW*`@Qn|yvl|G!82^59;tXA+-z``gN zM}ke<%RJ%=B?s|3EILTMGD~Lo78Yf>b7lI(~y7(61>P^57FV0>9|^DM$@QE>IpGd5Tn7Z zM0Oj|j(9JP-iFvDua*)dK|@k6^!BT-jA{{hIM4BL9Xw8Lf0WwYO6^`uy;}<}ZP{8M zx%pl#v?O(Y7rzl-(EpUWA9rl23CpS8y7@5Gf8%s*WGR`tef;L}2KOl0*Gl&N!rlF> zx&P#E+`WJp^(|=rD>>piDA6QHuY<3)cykqB2-9L2S-F2sT zA-t5?-bnnIYmz8$+6t6zNB(f_mybjkmA zgIJ}ecnB?p?Zf#rC|Lf8Do`up=5-F?8^?{6iKHDkw~q%sY)l^Up> z@x_leV@F{cNB%RIkRwRKO$QeqH>8NBl`GTL65(T-cD1UP{F8*H&6v<}OQvO562PZ z8OsWX)+8WqS!26}TzzN_;Hhz>O{O-7_uFLOvqB6^$T1|kb2k3vK>}z~Kpr7ZE{3!KD-q!QtQ$ujzSu&DEDw)XB+j;O^?? z$C0c~4uVj-n_TY%2Q&QNOJ4rJyu3-Hu|VwloW91Xjqh$#u4<7?nl^bN8)SHfSClxDCB&I&=-meveR*q=pj2GflQ&A!vDCcjPv%}r+R0&k!RhDK+ z*t^pgnS>r@mm<svB?1v+cNnDxi0%a;JI$2=`6%K(D}l}-~WWCnnB zYc}hS&UF$2*BX=au@=hK92gg!)SS4v<>CgS=B+%EDWlc)?2apUeP-&v dict: - pattern = re.compile(r""" - (?P^\S+) - | - (?P-{1,3})(?P\w+) - | - (?P\S+) - """, re.VERBOSE) - - tokens = pattern.findall(command) - if not tokens: - raise CommandParseError("Invalid command format") - - result = {} - args = {} - current_arg = None - - for token in tokens: - command_name, arg_prefix, arg_name, value = token - - if command_name: - if "command" in result: - raise CommandParseError("Multiple command names found") - result["command"] = command_name - - elif arg_name: - if current_arg: - raise CommandParseError(f"Argument {current_arg} has no value") - current_arg = f"{arg_prefix}{arg_name}" - - elif value: - if not current_arg: - raise CommandParseError(f"Unexpected value: {value}") - args[current_arg] = value - current_arg = None - - if current_arg: - raise CommandParseError(f"Argument {current_arg} has no value") - - result["args"] = args - return result - - -command_str = "run" -parsed = (command_str) -pprint(parsed) +x: LiteralString = '---' +m: LiteralString = input() +if m == '-': + x = m