mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
work on support args
This commit is contained in:
@@ -216,7 +216,7 @@ class AppSetups(AppValidators, AppPrinters):
|
||||
|
||||
|
||||
class App(AppSetters, AppNonStandardHandlers, AppSetups):
|
||||
def start_polling(self) -> None:
|
||||
def run_polling(self) -> None:
|
||||
self._pre_cycle_setup()
|
||||
while True:
|
||||
if self._repeat_command_groups_description:
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
__all__ = ["Orchestrator"]
|
||||
|
||||
|
||||
from argenta.orchestrator.entity import Orchestrator
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
__all__ = ["BooleanArgument", "PositionalArgument", "OptionalArgument"]
|
||||
|
||||
|
||||
from argenta.orchestrator.arguments.models import (BooleanArgument,
|
||||
PositionalArgument,
|
||||
OptionalArgument)
|
||||
@@ -0,0 +1,50 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Literal
|
||||
|
||||
|
||||
class BaseArgument(ABC):
|
||||
@abstractmethod
|
||||
def get_string_entity(self):
|
||||
"""
|
||||
Returns the string representation of the argument
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class PositionalArgument(BaseArgument):
|
||||
def __init__(self, name: str):
|
||||
"""
|
||||
Required argument at startup
|
||||
:param name: name of the argument, must not start with minus (-)
|
||||
"""
|
||||
self.name = name
|
||||
|
||||
def get_string_entity(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class OptionalArgument(BaseArgument):
|
||||
def __init__(self, name: str, prefix: Literal['-', '--', '---']):
|
||||
"""
|
||||
Optional argument, must have the value
|
||||
:param name: name of the argument
|
||||
:param prefix: prefix of the argument
|
||||
"""
|
||||
self.name = name
|
||||
self.prefix = prefix
|
||||
|
||||
def get_string_entity(self):
|
||||
return self.prefix + self.name
|
||||
|
||||
|
||||
class BooleanArgument(BaseArgument):
|
||||
def __init__(self, name: str):
|
||||
"""
|
||||
Boolean argument, does not require a value
|
||||
:param name: name of the argument
|
||||
"""
|
||||
self.name = name
|
||||
|
||||
def get_string_entity(self):
|
||||
return self.name
|
||||
@@ -0,0 +1,4 @@
|
||||
class ArgParse:
|
||||
def __init__(self, name: str, description: str):
|
||||
self.name = name
|
||||
self.description = description
|
||||
@@ -1,2 +1,43 @@
|
||||
from argparse import ArgumentParser
|
||||
|
||||
from argenta.app import App
|
||||
from argenta.orchestrator.argparse.arguments import (PositionalArgument,
|
||||
OptionalArgument,
|
||||
BooleanArgument)
|
||||
|
||||
|
||||
class Orchestrator:
|
||||
pass
|
||||
def __init__(self, *args: PositionalArgument | OptionalArgument | BooleanArgument):
|
||||
"""
|
||||
An orchestrator and configurator that defines the behavior of an integrated system, one level higher than the App
|
||||
:param args: logged command line arguments at startup
|
||||
"""
|
||||
self.args = args
|
||||
self.argparse: ArgumentParser = ArgumentParser()
|
||||
self._register_args()
|
||||
|
||||
@staticmethod
|
||||
def start_polling(app: App) -> None:
|
||||
"""
|
||||
Starting the user input processing cycle
|
||||
:param app: a running application
|
||||
:return:
|
||||
"""
|
||||
app.run_polling()
|
||||
|
||||
def get_args(self):
|
||||
return self.argparse.parse_args()
|
||||
|
||||
def _register_args(self):
|
||||
"""
|
||||
Registers initialized command line arguments
|
||||
:return:
|
||||
"""
|
||||
for arg in self.args:
|
||||
if type(arg) is PositionalArgument:
|
||||
self.argparse.add_argument(arg.get_string_entity())
|
||||
elif type(arg) is OptionalArgument:
|
||||
self.argparse.add_argument(arg.get_string_entity())
|
||||
elif type(arg) is BooleanArgument:
|
||||
self.argparse.add_argument(arg.get_string_entity(), action='store_const')
|
||||
|
||||
Reference in New Issue
Block a user