orionis 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- orionis/__init__.py +0 -0
- orionis/cli_manager.py +48 -0
- orionis/framework.py +45 -0
- orionis/luminate/__init__.py +0 -0
- orionis/luminate/app.py +0 -0
- orionis/luminate/bootstrap/__init__.py +0 -0
- orionis/luminate/bootstrap/parser.py +49 -0
- orionis/luminate/bootstrap/register.py +95 -0
- orionis/luminate/cache/__init__.py +0 -0
- orionis/luminate/cache/app/__init__.py +0 -0
- orionis/luminate/cache/app/config.py +96 -0
- orionis/luminate/cache/console/__init__.py +0 -0
- orionis/luminate/cache/console/commands.py +98 -0
- orionis/luminate/config/__init__.py +0 -0
- orionis/luminate/config/dataclass/__init__.py +0 -0
- orionis/luminate/config/dataclass/app.py +50 -0
- orionis/luminate/config/dataclass/auth.py +17 -0
- orionis/luminate/config/dataclass/cache.py +51 -0
- orionis/luminate/config/dataclass/cors.py +58 -0
- orionis/luminate/config/dataclass/database.py +203 -0
- orionis/luminate/config/dataclass/filesystems.py +102 -0
- orionis/luminate/config/dataclass/logging.py +107 -0
- orionis/luminate/config/dataclass/mail.py +81 -0
- orionis/luminate/config/dataclass/queue.py +63 -0
- orionis/luminate/config/dataclass/session.py +59 -0
- orionis/luminate/config/environment.py +110 -0
- orionis/luminate/config/sections.py +37 -0
- orionis/luminate/console/__init__.py +0 -0
- orionis/luminate/console/base/__init__.py +0 -0
- orionis/luminate/console/base/command.py +427 -0
- orionis/luminate/console/cache.py +132 -0
- orionis/luminate/console/command.py +40 -0
- orionis/luminate/console/command_filter.py +40 -0
- orionis/luminate/console/commands/__init__.py +0 -0
- orionis/luminate/console/commands/cache_clear.py +56 -0
- orionis/luminate/console/commands/help.py +59 -0
- orionis/luminate/console/commands/schedule_work.py +50 -0
- orionis/luminate/console/commands/tests.py +40 -0
- orionis/luminate/console/commands/version.py +39 -0
- orionis/luminate/console/exceptions/__init__.py +0 -0
- orionis/luminate/console/exceptions/cli_exception.py +125 -0
- orionis/luminate/console/kernel.py +32 -0
- orionis/luminate/console/output/__init__.py +0 -0
- orionis/luminate/console/output/console.py +426 -0
- orionis/luminate/console/output/executor.py +90 -0
- orionis/luminate/console/output/progress_bar.py +100 -0
- orionis/luminate/console/output/styles.py +95 -0
- orionis/luminate/console/parser.py +159 -0
- orionis/luminate/console/register.py +98 -0
- orionis/luminate/console/runner.py +126 -0
- orionis/luminate/console/scripts/__init__.py +0 -0
- orionis/luminate/console/scripts/management.py +94 -0
- orionis/luminate/console/tasks/__init__.py +0 -0
- orionis/luminate/console/tasks/scheduler.py +616 -0
- orionis/luminate/contracts/__init__.py +0 -0
- orionis/luminate/contracts/bootstrap/parser_interface.py +46 -0
- orionis/luminate/contracts/cache/__init__.py +0 -0
- orionis/luminate/contracts/cache/cache_commands_interface.py +69 -0
- orionis/luminate/contracts/config/__init__.py +0 -0
- orionis/luminate/contracts/config/config_interface.py +27 -0
- orionis/luminate/contracts/config/environment_interface.py +64 -0
- orionis/luminate/contracts/console/__init__.py +0 -0
- orionis/luminate/contracts/console/base_command_interface.py +448 -0
- orionis/luminate/contracts/console/cli_cache_interface.py +34 -0
- orionis/luminate/contracts/console/command_filter_interface.py +32 -0
- orionis/luminate/contracts/console/command_interface.py +36 -0
- orionis/luminate/contracts/console/console_interface.py +305 -0
- orionis/luminate/contracts/console/executor_interface.py +51 -0
- orionis/luminate/contracts/console/kernel_interface.py +32 -0
- orionis/luminate/contracts/console/management_interface.py +63 -0
- orionis/luminate/contracts/console/parser_interface.py +76 -0
- orionis/luminate/contracts/console/progress_bar_interface.py +66 -0
- orionis/luminate/contracts/console/register_interface.py +32 -0
- orionis/luminate/contracts/console/runner_interface.py +50 -0
- orionis/luminate/contracts/console/schedule_interface.py +317 -0
- orionis/luminate/contracts/console/task_manager_interface.py +37 -0
- orionis/luminate/contracts/facades/__init__.py +0 -0
- orionis/luminate/contracts/facades/env_interface.py +64 -0
- orionis/luminate/contracts/facades/log_interface.py +48 -0
- orionis/luminate/contracts/facades/paths_interface.py +141 -0
- orionis/luminate/contracts/facades/tests_interface.py +33 -0
- orionis/luminate/contracts/files/__init__.py +0 -0
- orionis/luminate/contracts/files/paths_interface.py +29 -0
- orionis/luminate/contracts/installer/__init__.py +0 -0
- orionis/luminate/contracts/installer/output_interface.py +125 -0
- orionis/luminate/contracts/installer/setup_interface.py +29 -0
- orionis/luminate/contracts/installer/upgrade_interface.py +24 -0
- orionis/luminate/contracts/log/__init__.py +0 -0
- orionis/luminate/contracts/log/logger_interface.py +33 -0
- orionis/luminate/contracts/pipelines/cli_pipeline_interface.py +84 -0
- orionis/luminate/contracts/publisher/__init__.py +0 -0
- orionis/luminate/contracts/publisher/pypi_publisher_interface.py +36 -0
- orionis/luminate/contracts/test/__init__.py +0 -0
- orionis/luminate/contracts/test/unit_test_interface.py +51 -0
- orionis/luminate/contracts/tools/__init__.py +0 -0
- orionis/luminate/contracts/tools/reflection_interface.py +343 -0
- orionis/luminate/contracts/tools/std_interface.py +56 -0
- orionis/luminate/facades/__init__.py +0 -0
- orionis/luminate/facades/environment.py +81 -0
- orionis/luminate/facades/log.py +56 -0
- orionis/luminate/facades/paths.py +268 -0
- orionis/luminate/facades/tests.py +48 -0
- orionis/luminate/files/__init__.py +0 -0
- orionis/luminate/files/paths.py +56 -0
- orionis/luminate/installer/__init__.py +0 -0
- orionis/luminate/installer/icon.ascii +11 -0
- orionis/luminate/installer/info.ascii +13 -0
- orionis/luminate/installer/output.py +188 -0
- orionis/luminate/installer/setup.py +191 -0
- orionis/luminate/installer/upgrade.py +42 -0
- orionis/luminate/log/__init__.py +0 -0
- orionis/luminate/log/logger.py +116 -0
- orionis/luminate/pipelines/__init__.py +0 -0
- orionis/luminate/pipelines/cli_pipeline.py +116 -0
- orionis/luminate/publisher/__init__.py +0 -0
- orionis/luminate/publisher/pypi.py +206 -0
- orionis/luminate/static/logos/flaskavel.png +0 -0
- orionis/luminate/test/__init__.py +0 -0
- orionis/luminate/test/exception.py +48 -0
- orionis/luminate/test/unit_test.py +108 -0
- orionis/luminate/tools/__init__.py +0 -0
- orionis/luminate/tools/reflection.py +390 -0
- orionis/luminate/tools/std.py +53 -0
- orionis-0.1.0.dist-info/LICENCE +21 -0
- orionis-0.1.0.dist-info/METADATA +27 -0
- orionis-0.1.0.dist-info/RECORD +133 -0
- orionis-0.1.0.dist-info/WHEEL +5 -0
- orionis-0.1.0.dist-info/entry_points.txt +2 -0
- orionis-0.1.0.dist-info/top_level.txt +2 -0
- tests/__init__.py +0 -0
- tests/tools/__init__.py +0 -0
- tests/tools/class_example.py +50 -0
- tests/tools/test_reflection.py +128 -0
@@ -0,0 +1,95 @@
|
|
1
|
+
from enum import Enum
|
2
|
+
|
3
|
+
class ANSIColors(Enum):
|
4
|
+
"""
|
5
|
+
ANSI escape codes for text and background styling in the terminal.
|
6
|
+
|
7
|
+
This Enum provides color codes for text styling in console applications,
|
8
|
+
including foreground (TEXT), background (BG), bold (TEXT_BOLD), and
|
9
|
+
additional text styles like underlining.
|
10
|
+
|
11
|
+
Attributes
|
12
|
+
----------
|
13
|
+
DEFAULT : str
|
14
|
+
Resets all colors and styles to default terminal settings.
|
15
|
+
|
16
|
+
Background Colors
|
17
|
+
-----------------
|
18
|
+
BG_INFO : str
|
19
|
+
Blue background, typically used for informational messages.
|
20
|
+
BG_ERROR : str
|
21
|
+
Red background, typically used for error messages.
|
22
|
+
BG_WARNING : str
|
23
|
+
Yellow background, typically used for warnings.
|
24
|
+
BG_SUCCESS : str
|
25
|
+
Green background, typically used for success messages.
|
26
|
+
|
27
|
+
Foreground Colors
|
28
|
+
-----------------
|
29
|
+
TEXT_INFO : str
|
30
|
+
Blue text, typically used for informational messages.
|
31
|
+
TEXT_ERROR : str
|
32
|
+
Bright red text, typically used for errors.
|
33
|
+
TEXT_WARNING : str
|
34
|
+
Yellow text, typically used for warnings.
|
35
|
+
TEXT_SUCCESS : str
|
36
|
+
Green text, typically used for success messages.
|
37
|
+
TEXT_WHITE : str
|
38
|
+
White text, useful for contrast.
|
39
|
+
TEXT_MUTED : str
|
40
|
+
Gray text, typically used for secondary/muted information.
|
41
|
+
|
42
|
+
Bold Foreground Colors
|
43
|
+
----------------------
|
44
|
+
TEXT_BOLD_INFO : str
|
45
|
+
Bold blue text for informational emphasis.
|
46
|
+
TEXT_BOLD_ERROR : str
|
47
|
+
Bold red text for error emphasis.
|
48
|
+
TEXT_BOLD_WARNING : str
|
49
|
+
Bold yellow text for warning emphasis.
|
50
|
+
TEXT_BOLD_SUCCESS : str
|
51
|
+
Bold green text for success emphasis.
|
52
|
+
TEXT_BOLD_WHITE : str
|
53
|
+
Bold white text for strong contrast.
|
54
|
+
TEXT_BOLD_MUTED : str
|
55
|
+
Bold gray text for muted yet emphasized information.
|
56
|
+
|
57
|
+
Additional Text Styles
|
58
|
+
----------------------
|
59
|
+
TEXT_BOLD : str
|
60
|
+
Bold text style.
|
61
|
+
TEXT_STYLE_UNDERLINE : str
|
62
|
+
Underlined text for emphasis.
|
63
|
+
TEXT_RESET : str
|
64
|
+
Resets text styles to default settings.
|
65
|
+
"""
|
66
|
+
|
67
|
+
DEFAULT = '\033[0m' # Reset all colors and styles
|
68
|
+
|
69
|
+
# Background Colors
|
70
|
+
BG_INFO = '\033[44m' # Blue background for INFO
|
71
|
+
BG_ERROR = '\033[41m' # Red background for ERROR
|
72
|
+
BG_FAIL = '\033[48;5;166m' # Red background for FAIL
|
73
|
+
BG_WARNING = '\033[43m' # Yellow background for WARNING
|
74
|
+
BG_SUCCESS = '\033[42m' # Green background for SUCCESS
|
75
|
+
|
76
|
+
# Foreground Text Colors
|
77
|
+
TEXT_INFO = '\033[34m' # Blue for informational messages
|
78
|
+
TEXT_ERROR = '\033[91m' # Bright red for errors
|
79
|
+
TEXT_WARNING = '\033[33m' # Yellow for warnings
|
80
|
+
TEXT_SUCCESS = '\033[32m' # Green for success
|
81
|
+
TEXT_WHITE = '\033[97m' # White text
|
82
|
+
TEXT_MUTED = '\033[90m' # Gray (muted) text
|
83
|
+
|
84
|
+
# Bold Foreground Text Colors
|
85
|
+
TEXT_BOLD_INFO = '\033[1;34m' # Bold blue for INFO
|
86
|
+
TEXT_BOLD_ERROR = '\033[1;91m' # Bold red for ERROR
|
87
|
+
TEXT_BOLD_WARNING = '\033[1;33m' # Bold yellow for WARNING
|
88
|
+
TEXT_BOLD_SUCCESS = '\033[1;32m' # Bold green for SUCCESS
|
89
|
+
TEXT_BOLD_WHITE = '\033[1;97m' # Bold white text
|
90
|
+
TEXT_BOLD_MUTED = '\033[1;90m' # Bold gray (muted) text
|
91
|
+
|
92
|
+
# Additional Text Styles
|
93
|
+
TEXT_BOLD = "\033[1m" # Bold text
|
94
|
+
TEXT_STYLE_UNDERLINE = '\033[4m' # Underline text
|
95
|
+
TEXT_RESET = "\033[0m" # Reset styles
|
@@ -0,0 +1,159 @@
|
|
1
|
+
import shlex
|
2
|
+
import types
|
3
|
+
import argparse
|
4
|
+
from io import StringIO
|
5
|
+
from contextlib import redirect_stderr
|
6
|
+
from orionis.luminate.contracts.console.parser_interface import IParser
|
7
|
+
|
8
|
+
class Parser(IParser):
|
9
|
+
"""
|
10
|
+
A command-line argument parser using argparse.
|
11
|
+
|
12
|
+
This class provides methods for dynamically registering arguments,
|
13
|
+
parsing positional and keyword arguments, and handling errors gracefully.
|
14
|
+
|
15
|
+
Attributes
|
16
|
+
----------
|
17
|
+
argparse : argparse.ArgumentParser
|
18
|
+
The argument parser instance used for defining and parsing arguments.
|
19
|
+
args : list
|
20
|
+
A list storing the command-line arguments to be parsed.
|
21
|
+
kwargs : dict
|
22
|
+
A dictionary containing keyword arguments.
|
23
|
+
registered_arguments : set
|
24
|
+
A set tracking registered argument names to prevent duplicates.
|
25
|
+
"""
|
26
|
+
|
27
|
+
def __init__(self, vars: dict, args: tuple, kwargs: dict):
|
28
|
+
"""
|
29
|
+
Initializes the Parser class.
|
30
|
+
|
31
|
+
Parameters
|
32
|
+
----------
|
33
|
+
vars : dict
|
34
|
+
A dictionary containing additional variables.
|
35
|
+
args : tuple
|
36
|
+
A tuple containing command-line arguments.
|
37
|
+
kwargs : dict
|
38
|
+
A dictionary containing keyword arguments.
|
39
|
+
"""
|
40
|
+
self.argparse = argparse.ArgumentParser(description='Orionis Commands Argument Parser')
|
41
|
+
self.vars = vars or {}
|
42
|
+
self.args = list(args)
|
43
|
+
self.kwargs = kwargs or {}
|
44
|
+
self.registered_arguments = set()
|
45
|
+
self.parsed_arguments = []
|
46
|
+
|
47
|
+
def setArguments(self, arguments: list):
|
48
|
+
"""
|
49
|
+
Registers command-line arguments dynamically.
|
50
|
+
|
51
|
+
Parameters
|
52
|
+
----------
|
53
|
+
arguments : list of tuple
|
54
|
+
A list of tuples where each tuple contains:
|
55
|
+
- str: The argument name (e.g., '--value')
|
56
|
+
- dict: A dictionary of options (e.g., {'type': int, 'required': True})
|
57
|
+
|
58
|
+
Raises
|
59
|
+
------
|
60
|
+
ValueError
|
61
|
+
If an argument is already registered.
|
62
|
+
"""
|
63
|
+
for arg, options in arguments:
|
64
|
+
if arg in self.registered_arguments:
|
65
|
+
raise ValueError(f"Duplicate argument detected: {arg}")
|
66
|
+
self.argparse.add_argument(arg, **options)
|
67
|
+
self.registered_arguments.add(arg)
|
68
|
+
|
69
|
+
def _validateType(self, value):
|
70
|
+
"""
|
71
|
+
Validates that a value is not an instance of a class, function, or lambda.
|
72
|
+
|
73
|
+
Parameters
|
74
|
+
----------
|
75
|
+
value : any
|
76
|
+
The value to be validated.
|
77
|
+
|
78
|
+
Raises
|
79
|
+
------
|
80
|
+
ValueError
|
81
|
+
If the value is a class instance, function, or lambda.
|
82
|
+
"""
|
83
|
+
if isinstance(value, (types.FunctionType, types.LambdaType, type)):
|
84
|
+
raise ValueError("Command arguments cannot be functions, lambdas, or class instances.")
|
85
|
+
|
86
|
+
def recognize(self):
|
87
|
+
"""
|
88
|
+
Processes and formats command-line arguments before parsing.
|
89
|
+
|
90
|
+
Raises
|
91
|
+
------
|
92
|
+
ValueError
|
93
|
+
If an argument does not follow the correct format.
|
94
|
+
"""
|
95
|
+
|
96
|
+
# If `args` is a single list inside a list, extract it
|
97
|
+
if isinstance(self.args, list) and len(self.args) == 1 and isinstance(self.args[0], list):
|
98
|
+
all_args:list = self.args[0]
|
99
|
+
first_arg:str = all_args[0]
|
100
|
+
|
101
|
+
if first_arg.endswith('.py') or first_arg in ['orionis']:
|
102
|
+
self.args = all_args[1:]
|
103
|
+
else:
|
104
|
+
self.args = all_args
|
105
|
+
|
106
|
+
# Merge `kwargs` with `vars`
|
107
|
+
if isinstance(self.vars, dict):
|
108
|
+
self.kwargs = {**self.vars, **self.kwargs}
|
109
|
+
else:
|
110
|
+
self.args = [self.vars, *self.args]
|
111
|
+
|
112
|
+
# Process each argument in `args`
|
113
|
+
formatted_args = []
|
114
|
+
for arg in self.args:
|
115
|
+
self._validateType(arg)
|
116
|
+
|
117
|
+
arg = str(arg).strip()
|
118
|
+
if arg.startswith('--') and '=' in arg[2:]:
|
119
|
+
formatted_args.append(arg)
|
120
|
+
else:
|
121
|
+
raise ValueError(f'Unrecognized argument: "{arg}". Expected format: --key="value"')
|
122
|
+
|
123
|
+
# Convert `kwargs` to `--key=value` format
|
124
|
+
for key, value in self.kwargs.items():
|
125
|
+
self._validateType(value)
|
126
|
+
formatted_args.append(f'--{key}={shlex.quote(str(value))}')
|
127
|
+
|
128
|
+
# Replace args with processed version
|
129
|
+
self.parsed_arguments = formatted_args
|
130
|
+
|
131
|
+
def get(self):
|
132
|
+
"""
|
133
|
+
Parses the collected command-line arguments.
|
134
|
+
|
135
|
+
Returns
|
136
|
+
-------
|
137
|
+
argparse.Namespace
|
138
|
+
The parsed arguments as an object where each argument is an attribute.
|
139
|
+
|
140
|
+
Raises
|
141
|
+
------
|
142
|
+
ValueError
|
143
|
+
If required arguments are missing or an error occurs during parsing,
|
144
|
+
it raises a customized error message including the original argparse error.
|
145
|
+
"""
|
146
|
+
stderr_capture = StringIO()
|
147
|
+
|
148
|
+
try:
|
149
|
+
with redirect_stderr(stderr_capture):
|
150
|
+
return self.argparse.parse_args(self.parsed_arguments)
|
151
|
+
|
152
|
+
except SystemExit:
|
153
|
+
error_message = stderr_capture.getvalue().strip()
|
154
|
+
array_message = error_message.split('error: ')
|
155
|
+
final_message = str(array_message[1]).replace('unrecognized', 'Unrecognized')
|
156
|
+
raise ValueError(f"Argument parsing failed | {final_message} | Required arguments: {', '.join(self.registered_arguments)}")
|
157
|
+
|
158
|
+
except Exception as e:
|
159
|
+
raise ValueError(f"An unexpected error occurred while parsing arguments: {str(e)}")
|
@@ -0,0 +1,98 @@
|
|
1
|
+
from orionis.luminate.console.base.command import BaseCommand
|
2
|
+
from orionis.luminate.cache.console.commands import CacheCommands
|
3
|
+
from orionis.luminate.contracts.console.register_interface import IRegister
|
4
|
+
|
5
|
+
class Register(IRegister):
|
6
|
+
"""
|
7
|
+
A class to register and manage command classes.
|
8
|
+
|
9
|
+
Attributes
|
10
|
+
----------
|
11
|
+
commands : dict
|
12
|
+
A dictionary storing registered command classes.
|
13
|
+
"""
|
14
|
+
|
15
|
+
def __init__(self, cache : CacheCommands = None):
|
16
|
+
"""
|
17
|
+
Initializes the Register instance and prepares the cache commands system.
|
18
|
+
"""
|
19
|
+
self.cache_commands = cache or CacheCommands()
|
20
|
+
|
21
|
+
def command(self, command_class):
|
22
|
+
"""
|
23
|
+
Registers a command class after validating its structure.
|
24
|
+
|
25
|
+
Parameters
|
26
|
+
----------
|
27
|
+
command_class : type
|
28
|
+
The command class to register. It must:
|
29
|
+
- Have a 'signature' attribute (str, containing only letters, numbers, and ':', with no spaces).
|
30
|
+
- Have a 'description' attribute (str).
|
31
|
+
- Implement a 'handle' method.
|
32
|
+
- Inherit from 'BaseCommand'.
|
33
|
+
|
34
|
+
Returns
|
35
|
+
-------
|
36
|
+
type
|
37
|
+
The registered command class.
|
38
|
+
|
39
|
+
Raises
|
40
|
+
------
|
41
|
+
ValueError
|
42
|
+
If 'signature' is missing, invalid, contains spaces, or is not a string.
|
43
|
+
If 'description' is missing or not a string.
|
44
|
+
If 'handle' method is missing.
|
45
|
+
TypeError
|
46
|
+
If the class does not inherit from 'BaseCommand'.
|
47
|
+
"""
|
48
|
+
|
49
|
+
# Ensure 'command_class' is actually a class
|
50
|
+
if not isinstance(command_class, type):
|
51
|
+
raise TypeError(f"Expected a class, but got {type(command_class).__name__}.")
|
52
|
+
|
53
|
+
# Validate 'signature' attribute
|
54
|
+
if not hasattr(command_class, 'signature') or not isinstance(command_class.signature, str):
|
55
|
+
raise ValueError(f"Class {command_class.__name__} must have a 'signature' attribute as a string.")
|
56
|
+
|
57
|
+
# Sanitaze signature
|
58
|
+
signature = command_class.signature.strip()
|
59
|
+
|
60
|
+
# Ensure signature contains only letters, numbers, and ':', with no spaces
|
61
|
+
if not signature or ' ' in signature or not all(c.isalnum() or c == ":" for c in signature):
|
62
|
+
raise ValueError(f"Invalid signature format: '{signature}'. Only letters, numbers, and ':' are allowed, with no spaces.")
|
63
|
+
|
64
|
+
# Validate 'description' attribute
|
65
|
+
if not hasattr(command_class, 'description') or not isinstance(command_class.description, str):
|
66
|
+
raise ValueError(f"Class {command_class.__name__} must have a 'description' attribute as a string.")
|
67
|
+
|
68
|
+
# Sanitaze signature
|
69
|
+
description = command_class.description.strip()
|
70
|
+
|
71
|
+
# Validate 'handle' method
|
72
|
+
if not hasattr(command_class, 'handle') or not callable(getattr(command_class, 'handle')):
|
73
|
+
raise ValueError(f"Class {command_class.__name__} must implement a 'handle' method.")
|
74
|
+
|
75
|
+
# Validate 'arguments' method
|
76
|
+
if hasattr(command_class, 'arguments') and callable(getattr(command_class, 'arguments')):
|
77
|
+
arguments = command_class().arguments()
|
78
|
+
else:
|
79
|
+
arguments = []
|
80
|
+
|
81
|
+
# Validate inheritance from 'BaseCommand'
|
82
|
+
if not issubclass(command_class, BaseCommand):
|
83
|
+
raise TypeError(f"Class {command_class.__name__} must inherit from 'BaseCommand'.")
|
84
|
+
|
85
|
+
# Register the command
|
86
|
+
self.cache_commands.register(
|
87
|
+
instance=command_class,
|
88
|
+
arguments=arguments,
|
89
|
+
description=description,
|
90
|
+
signature=signature
|
91
|
+
)
|
92
|
+
|
93
|
+
# Return Class
|
94
|
+
return command_class
|
95
|
+
|
96
|
+
|
97
|
+
# Return Decorator.
|
98
|
+
register = Register()
|
@@ -0,0 +1,126 @@
|
|
1
|
+
import time
|
2
|
+
from orionis.luminate.facades.log import Log
|
3
|
+
from orionis.luminate.console.output.console import Console
|
4
|
+
from orionis.luminate.console.output.executor import Executor
|
5
|
+
from orionis.luminate.pipelines.cli_pipeline import CLIPipeline
|
6
|
+
from orionis.luminate.console.command_filter import CommandFilter
|
7
|
+
from orionis.luminate.contracts.console.runner_interface import ICLIRunner
|
8
|
+
|
9
|
+
class CLIRunner(ICLIRunner):
|
10
|
+
"""
|
11
|
+
CLIRunner manages the execution of CLI commands in Orionis.
|
12
|
+
|
13
|
+
This class:
|
14
|
+
- Parses command-line arguments or function parameters.
|
15
|
+
- Executes commands through the `CLIPipeline`.
|
16
|
+
- Logs execution status and errors.
|
17
|
+
|
18
|
+
Methods
|
19
|
+
-------
|
20
|
+
handle(signature: str = None, vars: dict = {}, *args, **kwargs)
|
21
|
+
Processes and executes a CLI command based on provided arguments.
|
22
|
+
"""
|
23
|
+
|
24
|
+
@staticmethod
|
25
|
+
def handle(signature: str = None, vars: dict = {}, *args, **kwargs):
|
26
|
+
"""
|
27
|
+
Processes and executes a CLI command.
|
28
|
+
|
29
|
+
This method:
|
30
|
+
- Determines whether the command is invoked from `sys.argv` or as a function.
|
31
|
+
- Extracts the command signature and arguments.
|
32
|
+
- Executes the command pipeline.
|
33
|
+
- Logs execution status and handles errors.
|
34
|
+
|
35
|
+
Parameters
|
36
|
+
----------
|
37
|
+
signature : str, optional
|
38
|
+
The command signature (default is None, meaning it is extracted from `sys.argv`).
|
39
|
+
vars : dict, optional
|
40
|
+
Named arguments for the command (default is an empty dictionary).
|
41
|
+
*args
|
42
|
+
Additional arguments for the command.
|
43
|
+
**kwargs
|
44
|
+
Additional keyword arguments for the command.
|
45
|
+
|
46
|
+
Returns
|
47
|
+
-------
|
48
|
+
Any
|
49
|
+
The output of the executed command.
|
50
|
+
|
51
|
+
Raises
|
52
|
+
------
|
53
|
+
ValueError
|
54
|
+
If no command signature is provided.
|
55
|
+
Exception
|
56
|
+
If an unexpected error occurs during execution.
|
57
|
+
"""
|
58
|
+
|
59
|
+
try:
|
60
|
+
|
61
|
+
# Exclude commands from Printing
|
62
|
+
exclude_running = CommandFilter.isExcluded(signature)
|
63
|
+
|
64
|
+
# Determine if command is being executed from sys.argv
|
65
|
+
sys_argv = signature is None
|
66
|
+
|
67
|
+
# Start execution timer
|
68
|
+
start_time = time.perf_counter()
|
69
|
+
|
70
|
+
# Handle command signature extraction from sys.argv
|
71
|
+
if sys_argv:
|
72
|
+
|
73
|
+
# Extract command signature and arguments from sys.argv
|
74
|
+
if not args or len(args[0]) <= 1:
|
75
|
+
raise ValueError("No command signature specified.")
|
76
|
+
|
77
|
+
# Extract command signature and arguments
|
78
|
+
args_list = args[0]
|
79
|
+
signature, *args = args_list[1:]
|
80
|
+
|
81
|
+
# Log command execution start
|
82
|
+
Log.info(f"Running command: {signature}")
|
83
|
+
|
84
|
+
if not exclude_running:
|
85
|
+
Executor.running(program=signature)
|
86
|
+
|
87
|
+
# Initialize command pipeline
|
88
|
+
pipeline = CLIPipeline().getCommand(signature)
|
89
|
+
|
90
|
+
# Parse arguments based on invocation type
|
91
|
+
if sys_argv:
|
92
|
+
pipeline.parseArguments(*args)
|
93
|
+
else:
|
94
|
+
pipeline.parseArguments(vars, *args, **kwargs)
|
95
|
+
|
96
|
+
# Execute the command
|
97
|
+
output = pipeline.execute()
|
98
|
+
|
99
|
+
# Log successful execution
|
100
|
+
Log.success(f"Command executed successfully: {signature}")
|
101
|
+
|
102
|
+
# Calculate execution time
|
103
|
+
if not exclude_running:
|
104
|
+
elapsed_time = round(time.perf_counter() - start_time, 2)
|
105
|
+
Executor.done(program=signature, time=f"{elapsed_time}s")
|
106
|
+
|
107
|
+
# Return command output
|
108
|
+
return output
|
109
|
+
|
110
|
+
except ValueError as e:
|
111
|
+
|
112
|
+
# Handle missing or invalid command signature
|
113
|
+
Log.error(f"Command failed: {signature or 'Unknown'}, Value Error: {e}")
|
114
|
+
if not exclude_running:
|
115
|
+
Console.error(message=f"Value Error: {e}")
|
116
|
+
elapsed_time = round(time.perf_counter() - start_time, 2)
|
117
|
+
Executor.fail(program=signature or "Unknown", time=f"{elapsed_time}s")
|
118
|
+
|
119
|
+
except Exception as e:
|
120
|
+
|
121
|
+
# Handle unexpected errors
|
122
|
+
Log.error(f"Command failed: {signature or 'Unknown'}, Execution Error: {e}")
|
123
|
+
if not exclude_running:
|
124
|
+
Console.error(message=f"Execution Error: {e}")
|
125
|
+
elapsed_time = round(time.perf_counter() - start_time, 2)
|
126
|
+
Executor.fail(program=signature or "Unknown", time=f"{elapsed_time}s")
|
File without changes
|
@@ -0,0 +1,94 @@
|
|
1
|
+
from orionis.luminate.installer.setup import Setup
|
2
|
+
from orionis.luminate.installer.output import Output
|
3
|
+
from orionis.luminate.installer.upgrade import Upgrade
|
4
|
+
from orionis.luminate.contracts.console.management_interface import IManagement
|
5
|
+
|
6
|
+
class Management(IManagement):
|
7
|
+
"""
|
8
|
+
Management class responsible for handling framework-related operations.
|
9
|
+
|
10
|
+
This class provides methods to display the framework version, execute upgrades,
|
11
|
+
create new applications, and display additional information.
|
12
|
+
|
13
|
+
Attributes
|
14
|
+
----------
|
15
|
+
output : Output
|
16
|
+
Instance of Output to manage command-line display messages.
|
17
|
+
"""
|
18
|
+
|
19
|
+
def __init__(self, output = Output):
|
20
|
+
"""
|
21
|
+
Initialize the Management class with an output handler.
|
22
|
+
|
23
|
+
Parameters
|
24
|
+
----------
|
25
|
+
output : Output
|
26
|
+
An instance of Output to handle command-line messages.
|
27
|
+
"""
|
28
|
+
self.output = output
|
29
|
+
|
30
|
+
def displayVersion(self) -> str:
|
31
|
+
"""
|
32
|
+
Display the current version of the framework in ASCII format.
|
33
|
+
|
34
|
+
Returns
|
35
|
+
-------
|
36
|
+
str
|
37
|
+
The ASCII representation of the framework version.
|
38
|
+
|
39
|
+
Raises
|
40
|
+
------
|
41
|
+
Exception
|
42
|
+
If an error occurs while generating the ASCII version output.
|
43
|
+
"""
|
44
|
+
try:
|
45
|
+
return self.output.asciiIco()
|
46
|
+
except Exception as e:
|
47
|
+
raise RuntimeError(f"Failed to display version: {e}")
|
48
|
+
|
49
|
+
def executeUpgrade(self) -> None:
|
50
|
+
"""
|
51
|
+
Execute the framework upgrade process to the latest version.
|
52
|
+
|
53
|
+
Raises
|
54
|
+
------
|
55
|
+
Exception
|
56
|
+
If an error occurs during the upgrade process.
|
57
|
+
"""
|
58
|
+
try:
|
59
|
+
Upgrade.execute()
|
60
|
+
except Exception as e:
|
61
|
+
raise RuntimeError(f"Upgrade process failed: {e}")
|
62
|
+
|
63
|
+
def createNewApp(self, name_app: str = "example-app") -> None:
|
64
|
+
"""
|
65
|
+
Create a new application with the specified name.
|
66
|
+
|
67
|
+
Parameters
|
68
|
+
----------
|
69
|
+
name_app : str, optional
|
70
|
+
The name of the new application (default is "example-app").
|
71
|
+
|
72
|
+
Raises
|
73
|
+
------
|
74
|
+
Exception
|
75
|
+
If an error occurs during the application setup.
|
76
|
+
"""
|
77
|
+
try:
|
78
|
+
Setup(name_app).handle()
|
79
|
+
except Exception as e:
|
80
|
+
raise RuntimeError(f"Failed to create application '{name_app}': {e}")
|
81
|
+
|
82
|
+
def displayInfo(self) -> None:
|
83
|
+
"""
|
84
|
+
Display additional framework information in ASCII format.
|
85
|
+
|
86
|
+
Raises
|
87
|
+
------
|
88
|
+
Exception
|
89
|
+
If an error occurs while displaying information.
|
90
|
+
"""
|
91
|
+
try:
|
92
|
+
self.output.asciiInfo()
|
93
|
+
except Exception as e:
|
94
|
+
raise RuntimeError(f"Failed to display information: {e}")
|
File without changes
|