mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
big step
This commit is contained in:
@@ -6,23 +6,24 @@ from argenta.orchestrator.argparse.arguments.models import (BooleanArgument,
|
||||
|
||||
|
||||
class ArgParse:
|
||||
def __init__(self, name: str = 'Argenta',
|
||||
def __init__(self,
|
||||
processed_args: list[PositionalArgument | OptionalArgument | BooleanArgument],
|
||||
name: str = 'Argenta',
|
||||
description: str = 'Argenta available arguments',
|
||||
epilog: str = 'github.com/koloideal/Argenta | made by kolo',
|
||||
args: list[PositionalArgument | OptionalArgument | BooleanArgument] = None) -> None:
|
||||
epilog: str = 'github.com/koloideal/Argenta | made by kolo') -> None:
|
||||
"""
|
||||
Cmd argument parser and configurator at startup
|
||||
:param name: the name of the ArgParse instance
|
||||
:param description: the description of the ArgParse instance
|
||||
:param epilog: the epilog of the ArgParse instance
|
||||
:param args: registered and processed arguments
|
||||
:param processed_args: registered and processed arguments
|
||||
"""
|
||||
self.name = name
|
||||
self.description = description
|
||||
self.epilog = epilog
|
||||
|
||||
self.entity = ArgumentParser(prog=name, description=description, epilog=epilog)
|
||||
self.args: list[PositionalArgument | OptionalArgument | BooleanArgument] | None = args
|
||||
self.entity: ArgumentParser = ArgumentParser(prog=name, description=description, epilog=epilog)
|
||||
self.args: list[PositionalArgument | OptionalArgument | BooleanArgument] | None = processed_args
|
||||
|
||||
def set_args(self, *args: PositionalArgument | OptionalArgument | BooleanArgument):
|
||||
"""
|
||||
@@ -37,6 +38,8 @@ class ArgParse:
|
||||
Registers initialized command line arguments
|
||||
:return:
|
||||
"""
|
||||
if not self.args:
|
||||
return
|
||||
for arg in self.args:
|
||||
if type(arg) is PositionalArgument:
|
||||
self.entity.add_argument(arg.get_string_entity())
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
from argparse import Namespace
|
||||
|
||||
from argenta.app import App
|
||||
from argenta.orchestrator.argparse import ArgParse
|
||||
|
||||
|
||||
class Orchestrator:
|
||||
def __init__(self, arg_parser: ArgParse):
|
||||
def __init__(self, arg_parser: ArgParse = False):
|
||||
"""
|
||||
An orchestrator and configurator that defines the behavior of an integrated system, one level higher than the App
|
||||
:param arg_parser: Cmd argument parser and configurator at startup
|
||||
"""
|
||||
self.arg_parser: ArgParse = arg_parser
|
||||
self.arg_parser.register_args()
|
||||
self.arg_parser: ArgParse | False = arg_parser
|
||||
if arg_parser:
|
||||
self.arg_parser.register_args()
|
||||
|
||||
@staticmethod
|
||||
def start_polling(app: App) -> None:
|
||||
@@ -20,10 +23,13 @@ class Orchestrator:
|
||||
"""
|
||||
app.run_polling()
|
||||
|
||||
def get_args(self):
|
||||
def get_input_args(self) -> Namespace | None:
|
||||
"""
|
||||
Returns the arguments parsed
|
||||
:return:
|
||||
"""
|
||||
return self.arg_parser.entity.parse_args()
|
||||
if self.arg_parser:
|
||||
return self.arg_parser.entity.parse_args()
|
||||
else:
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user