mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
step by step
This commit is contained in:
@@ -1,11 +1,29 @@
|
||||
from argparse import ArgumentParser, Namespace
|
||||
from typing import Self
|
||||
|
||||
from argenta.orchestrator.argparser.arguments.models import (
|
||||
BaseArgument,
|
||||
BooleanArgument,
|
||||
InputArgument,
|
||||
ValueArgument,
|
||||
RequiredArgument,
|
||||
)
|
||||
|
||||
|
||||
class ArgSpace:
|
||||
def __init__(self, all_arguments: list[InputArgument]) -> None:
|
||||
self.all_arguments = all_arguments
|
||||
|
||||
@classmethod
|
||||
def from_namespace(cls, namespace: Namespace,
|
||||
processed_args: list[RequiredArgument | ValueArgument | BooleanArgument]) -> Self:
|
||||
name_type_paired_args: dict[str, type[BaseArgument]] = {
|
||||
arg.name: type(arg)
|
||||
for arg in processed_args
|
||||
}
|
||||
return cls([InputArgument(name, value, name_type_paired_args[name])
|
||||
for name, value in vars(namespace).items()])
|
||||
|
||||
|
||||
class ArgParser:
|
||||
def __init__(
|
||||
@@ -31,13 +49,13 @@ class ArgParser:
|
||||
|
||||
for arg in processed_args:
|
||||
if isinstance(arg, BooleanArgument):
|
||||
_ = self._entity.add_argument(arg.string_entity,
|
||||
_ = self._entity.add_argument(arg.name,
|
||||
action=arg.action,
|
||||
help=arg.help,
|
||||
required=arg.is_required,
|
||||
deprecated=arg.is_deprecated)
|
||||
else:
|
||||
_ = self._entity.add_argument(arg.string_entity,
|
||||
_ = self._entity.add_argument(arg.name,
|
||||
action=arg.action,
|
||||
help=arg.help,
|
||||
default=arg.default,
|
||||
@@ -45,5 +63,7 @@ class ArgParser:
|
||||
required=arg.is_required,
|
||||
deprecated=arg.is_deprecated)
|
||||
|
||||
def parse_args(self) -> Namespace:
|
||||
return self._entity.parse_args()
|
||||
def parse_args(self) -> ArgSpace:
|
||||
return ArgSpace.from_namespace(namespace=self._entity.parse_args(),
|
||||
processed_args=self._processed_args)
|
||||
|
||||
Reference in New Issue
Block a user