cli-ih 0.6.1.1__tar.gz → 0.6.1.2__tar.gz
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.
- {cli_ih-0.6.1.1 → cli_ih-0.6.1.2}/PKG-INFO +1 -1
- {cli_ih-0.6.1.1 → cli_ih-0.6.1.2}/cli_ih/Input_Handler.py +35 -15
- {cli_ih-0.6.1.1 → cli_ih-0.6.1.2}/cli_ih.egg-info/PKG-INFO +1 -1
- {cli_ih-0.6.1.1 → cli_ih-0.6.1.2}/pyproject.toml +1 -1
- {cli_ih-0.6.1.1 → cli_ih-0.6.1.2}/README.md +0 -0
- {cli_ih-0.6.1.1 → cli_ih-0.6.1.2}/cli_ih/__init__.py +0 -0
- {cli_ih-0.6.1.1 → cli_ih-0.6.1.2}/cli_ih.egg-info/SOURCES.txt +0 -0
- {cli_ih-0.6.1.1 → cli_ih-0.6.1.2}/cli_ih.egg-info/dependency_links.txt +0 -0
- {cli_ih-0.6.1.1 → cli_ih-0.6.1.2}/cli_ih.egg-info/top_level.txt +0 -0
- {cli_ih-0.6.1.1 → cli_ih-0.6.1.2}/setup.cfg +0 -0
|
@@ -52,17 +52,20 @@ class InputHandler:
|
|
|
52
52
|
else:
|
|
53
53
|
print(f"[EXEPTION]: {msg}: {e}")
|
|
54
54
|
|
|
55
|
-
def __register_cmd(self, name: str, func: Callable, description: str = ""):
|
|
55
|
+
def __register_cmd(self, name: str, func: Callable, description: str = "", legacy=False):
|
|
56
|
+
name = name.lower()
|
|
56
57
|
if not description:
|
|
57
58
|
description = "A command"
|
|
58
59
|
if ' ' in name:
|
|
59
60
|
raise SyntaxError("Command name must not have spaces")
|
|
60
|
-
self.commands
|
|
61
|
+
if name in self.commands:
|
|
62
|
+
raise SyntaxError(f"Command '{name}' is already registered. If theese commands have a different case and they need to stay the same, downgrade the package version to 0.5.x")
|
|
63
|
+
self.commands[name] = {"cmd": func, "description": description, "legacy": legacy}
|
|
61
64
|
|
|
62
65
|
def register_command(self, name: str, func: Callable, description: str = ""):
|
|
63
66
|
"""Registers a command with its associated function."""
|
|
64
67
|
warnings.warn("Registering commands with `register_command` is deprecated, and will be removed in the next big update.", DeprecationWarning, 2)
|
|
65
|
-
self.__register_cmd(name, func, description)
|
|
68
|
+
self.__register_cmd(name, func, description, legacy=True)
|
|
66
69
|
|
|
67
70
|
def command(self, *, name: str = "", description: str = ""):
|
|
68
71
|
"""Registers a command with its associated function as a decorator."""
|
|
@@ -84,19 +87,36 @@ class InputHandler:
|
|
|
84
87
|
command = commands.get(name)
|
|
85
88
|
if command:
|
|
86
89
|
func = command.get("cmd")
|
|
90
|
+
is_legacy = command.get("legacy", False)
|
|
87
91
|
if callable(func):
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
92
|
+
if is_legacy:
|
|
93
|
+
try:
|
|
94
|
+
sig = inspect.signature(func)
|
|
95
|
+
sig.bind(args)
|
|
96
|
+
except TypeError as e:
|
|
97
|
+
self.__warning(f"Argument error for legacy command '{name}': {e}")
|
|
98
|
+
return
|
|
99
|
+
|
|
100
|
+
try:
|
|
101
|
+
warnings.warn("This way of running commands id Deprecated. And should be changed to the new decorator way.", DeprecationWarning, 2)
|
|
102
|
+
func(args)
|
|
103
|
+
except HandlerClosed as e:
|
|
104
|
+
raise e
|
|
105
|
+
except Exception as e:
|
|
106
|
+
self.__exeption(f"An error occurred in legacy command '{name}'", e)
|
|
107
|
+
else:
|
|
108
|
+
try:
|
|
109
|
+
sig = inspect.signature(func)
|
|
110
|
+
sig.bind(*args)
|
|
111
|
+
except TypeError as e:
|
|
112
|
+
self.__warning(f"Argument error for command '{name}': {e}")
|
|
113
|
+
return
|
|
114
|
+
try:
|
|
115
|
+
func(*args)
|
|
116
|
+
except HandlerClosed as e:
|
|
117
|
+
raise e
|
|
118
|
+
except Exception as e:
|
|
119
|
+
self.__exeption(f"An error occurred in command '{name}'", e)
|
|
100
120
|
else:
|
|
101
121
|
raise ValueError(f"The command '{name}' is not callable.")
|
|
102
122
|
else:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|