mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
work on v0.3.0
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
from .params.flag.entity import Flag
|
||||
from .params.flags_group.entity import FlagsGroup
|
||||
from .exceptions import (InvalidCommandInstanceException,
|
||||
InvalidDescriptionInstanceException,
|
||||
InvalidFlagsInstanceException)
|
||||
|
||||
|
||||
class Command:
|
||||
def __init__(self, command: str,
|
||||
description: str | None = None,
|
||||
flags: Flag | FlagsGroup | None = None):
|
||||
self._command = command
|
||||
self._description = description
|
||||
self._flags = flags
|
||||
|
||||
def get_string_entity(self):
|
||||
return self._command
|
||||
|
||||
def get_description(self):
|
||||
if not self._description:
|
||||
description = f'description for "{self._command}" command'
|
||||
return description
|
||||
else:
|
||||
return self._description
|
||||
|
||||
def get_flags(self):
|
||||
return self._flags
|
||||
|
||||
def validate_commands_params(self):
|
||||
if not isinstance(self._command, str):
|
||||
raise InvalidCommandInstanceException(self._command)
|
||||
if isinstance(self._description, str):
|
||||
raise InvalidDescriptionInstanceException()
|
||||
if isinstance(self._flags, Flag) or isinstance(self._flags, FlagsGroup):
|
||||
raise InvalidFlagsInstanceException
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
class InvalidCommandInstanceException(Exception):
|
||||
def __str__(self):
|
||||
return "Invalid Command Instance"
|
||||
|
||||
|
||||
class InvalidDescriptionInstanceException(Exception):
|
||||
def __str__(self):
|
||||
return "Invalid Description Instance"
|
||||
|
||||
|
||||
class InvalidFlagsInstanceException(Exception):
|
||||
def __str__(self):
|
||||
return "Invalid Flags Instance"
|
||||
@@ -0,0 +1,40 @@
|
||||
from typing import Literal
|
||||
|
||||
|
||||
class Flag:
|
||||
def __init__(self, flag_name: str,
|
||||
flag_prefix: Literal['-', '--', '---'] = '-',
|
||||
ignore_flag_value_register: bool = False,
|
||||
possible_flag_values: list[str] = False):
|
||||
self.flag_name = flag_name
|
||||
self.flag_prefix = flag_prefix
|
||||
self.possible_flag_values = possible_flag_values
|
||||
self.ignore_flag_value_register = ignore_flag_value_register
|
||||
|
||||
def get_string_entity(self):
|
||||
if self.ignore_flag_value_register:
|
||||
string_entity: str = self.flag_prefix + self.flag_name.lower()
|
||||
else:
|
||||
string_entity: str = self.flag_prefix + self.flag_name
|
||||
return string_entity
|
||||
|
||||
def validate_input_flag_value(self, input_flag_value: str):
|
||||
if self.possible_flag_values:
|
||||
if self.ignore_flag_value_register:
|
||||
if input_flag_value.lower() in [x.lower() for x in self.possible_flag_values]:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
if input_flag_value in self.possible_flag_values:
|
||||
return True
|
||||
else:
|
||||
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())
|
||||
@@ -0,0 +1,3 @@
|
||||
class FlagsGroup:
|
||||
def __init__(self, flags):
|
||||
self.flags = flags
|
||||
Reference in New Issue
Block a user