mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
work on v0.3.0
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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())
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -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
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -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"
|
||||
Reference in New Issue
Block a user