cli-ih 0.6.0.2__tar.gz → 0.6.1.1__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.0.2 → cli_ih-0.6.1.1}/PKG-INFO +1 -1
- {cli_ih-0.6.0.2 → cli_ih-0.6.1.1}/cli_ih/Input_Handler.py +17 -15
- {cli_ih-0.6.0.2 → cli_ih-0.6.1.1}/cli_ih.egg-info/PKG-INFO +1 -1
- {cli_ih-0.6.0.2 → cli_ih-0.6.1.1}/pyproject.toml +1 -1
- {cli_ih-0.6.0.2 → cli_ih-0.6.1.1}/README.md +0 -0
- {cli_ih-0.6.0.2 → cli_ih-0.6.1.1}/cli_ih/__init__.py +0 -0
- {cli_ih-0.6.0.2 → cli_ih-0.6.1.1}/cli_ih.egg-info/SOURCES.txt +0 -0
- {cli_ih-0.6.0.2 → cli_ih-0.6.1.1}/cli_ih.egg-info/dependency_links.txt +0 -0
- {cli_ih-0.6.0.2 → cli_ih-0.6.1.1}/cli_ih.egg-info/top_level.txt +0 -0
- {cli_ih-0.6.0.2 → cli_ih-0.6.1.1}/setup.cfg +0 -0
|
@@ -52,22 +52,25 @@ class InputHandler:
|
|
|
52
52
|
else:
|
|
53
53
|
print(f"[EXEPTION]: {msg}: {e}")
|
|
54
54
|
|
|
55
|
-
def
|
|
56
|
-
"""Registers a command with its associated function."""
|
|
57
|
-
warnings.warn("Registering commands with `register_command` is deprecated, and will be removed in the next big update.", DeprecationWarning, 2)
|
|
55
|
+
def __register_cmd(self, name: str, func: Callable, description: str = ""):
|
|
58
56
|
if not description:
|
|
59
57
|
description = "A command"
|
|
60
58
|
if ' ' in name:
|
|
61
59
|
raise SyntaxError("Command name must not have spaces")
|
|
62
60
|
self.commands[name] = {"cmd": func, "description": description}
|
|
63
61
|
|
|
62
|
+
def register_command(self, name: str, func: Callable, description: str = ""):
|
|
63
|
+
"""Registers a command with its associated function."""
|
|
64
|
+
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)
|
|
66
|
+
|
|
64
67
|
def command(self, *, name: str = "", description: str = ""):
|
|
65
68
|
"""Registers a command with its associated function as a decorator."""
|
|
66
69
|
def decorator(func: Callable):
|
|
67
70
|
lname = name
|
|
68
71
|
if not lname:
|
|
69
72
|
lname = func.__name__
|
|
70
|
-
self.
|
|
73
|
+
self.__register_cmd(lname, func, description)
|
|
71
74
|
return func
|
|
72
75
|
return decorator
|
|
73
76
|
|
|
@@ -82,12 +85,14 @@ class InputHandler:
|
|
|
82
85
|
if command:
|
|
83
86
|
func = command.get("cmd")
|
|
84
87
|
if callable(func):
|
|
85
|
-
#if str(inspect.signature(func)) == "()":
|
|
86
|
-
#raise MissingParameter(f"Command '{name}' must accept an 'args' parameter")
|
|
87
88
|
try:
|
|
88
|
-
func
|
|
89
|
+
sig = inspect.signature(func)
|
|
90
|
+
sig.bind(*args)
|
|
89
91
|
except TypeError as e:
|
|
90
|
-
self.
|
|
92
|
+
self.__warning(f"Argument error for command '{name}': {e}")
|
|
93
|
+
return
|
|
94
|
+
try:
|
|
95
|
+
func(*args)
|
|
91
96
|
except HandlerClosed as e:
|
|
92
97
|
raise e
|
|
93
98
|
except Exception as e:
|
|
@@ -131,14 +136,14 @@ class InputHandler:
|
|
|
131
136
|
|
|
132
137
|
def register_default_commands(self):
|
|
133
138
|
@self.command(name="help", description="Displays all the available commands")
|
|
134
|
-
def help(
|
|
139
|
+
def help():
|
|
135
140
|
str_out = "Available commands:\n"
|
|
136
141
|
for command, data in self.commands.items():
|
|
137
142
|
str_out += f" {command}: {data['description']}\n"
|
|
138
143
|
print(str_out)
|
|
139
144
|
|
|
140
145
|
@self.command(name="debug", description="If a logger is present changes the logging level to DEBUG.")
|
|
141
|
-
def debug_mode(
|
|
146
|
+
def debug_mode():
|
|
142
147
|
logger = self.global_logger
|
|
143
148
|
if not logger:
|
|
144
149
|
return self.__warning("No logger defined for this InputHandler instance.")
|
|
@@ -158,8 +163,5 @@ class InputHandler:
|
|
|
158
163
|
self.__info(message)
|
|
159
164
|
|
|
160
165
|
@self.command(name="exit", description="Exits the Input Handler irreversibly.")
|
|
161
|
-
def exit_thread(
|
|
162
|
-
raise HandlerClosed("Handler was closed with exit command.")
|
|
163
|
-
# self.register_command("help", help, "Displays all the available commands")
|
|
164
|
-
# self.register_command("debug", debug_mode, "Changes the logging level to DEBUG.")
|
|
165
|
-
# self.register_command("exit", exit_thread, "Exits the Input Handler irreversibly.")
|
|
166
|
+
def exit_thread():
|
|
167
|
+
raise HandlerClosed("Handler was closed with exit command.")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|