cli-ih 0.6.0.1__py3-none-any.whl → 0.6.0.2.1__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.
- cli_ih/Input_Handler.py +8 -4
- {cli_ih-0.6.0.1.dist-info → cli_ih-0.6.0.2.1.dist-info}/METADATA +3 -3
- cli_ih-0.6.0.2.1.dist-info/RECORD +6 -0
- cli_ih-0.6.0.1.dist-info/RECORD +0 -6
- {cli_ih-0.6.0.1.dist-info → cli_ih-0.6.0.2.1.dist-info}/WHEEL +0 -0
- {cli_ih-0.6.0.1.dist-info → cli_ih-0.6.0.2.1.dist-info}/top_level.txt +0 -0
cli_ih/Input_Handler.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from typing import Callable
|
|
2
|
-
import logging
|
|
2
|
+
import logging, warnings
|
|
3
3
|
|
|
4
4
|
class HandlerClosed(Exception): ...
|
|
5
5
|
class MissingParameter(Exception): ...
|
|
@@ -52,21 +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."""
|
|
55
|
+
def __register_cmd(self, name: str, func: Callable, description: str = ""):
|
|
57
56
|
if not description:
|
|
58
57
|
description = "A command"
|
|
59
58
|
if ' ' in name:
|
|
60
59
|
raise SyntaxError("Command name must not have spaces")
|
|
61
60
|
self.commands[name] = {"cmd": func, "description": description}
|
|
62
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
|
+
|
|
63
67
|
def command(self, *, name: str = "", description: str = ""):
|
|
64
68
|
"""Registers a command with its associated function as a decorator."""
|
|
65
69
|
def decorator(func: Callable):
|
|
66
70
|
lname = name
|
|
67
71
|
if not lname:
|
|
68
72
|
lname = func.__name__
|
|
69
|
-
self.
|
|
73
|
+
self.__register_cmd(lname, func, description)
|
|
70
74
|
return func
|
|
71
75
|
return decorator
|
|
72
76
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cli_ih
|
|
3
|
-
Version: 0.6.0.1
|
|
3
|
+
Version: 0.6.0.2.1
|
|
4
4
|
Summary: A background command handler for python's command-line interface.
|
|
5
5
|
Author-email: Hotment <michatchuplay@gmail.com>
|
|
6
6
|
Requires-Python: >=3.8
|
|
@@ -33,7 +33,7 @@ def greet(args):
|
|
|
33
33
|
|
|
34
34
|
handler = InputHandler(cursor="> ")
|
|
35
35
|
# NEW
|
|
36
|
-
@handler.command(name="add", description="Performs the `+` operator on the first 2 arguments.")
|
|
36
|
+
@handler.command(name="add", description="Performs the `+` operator on the first 2 arguments.") # The name param will use the func name if its not provided
|
|
37
37
|
def add(args):
|
|
38
38
|
print(int(args[0])+int(args[1]))
|
|
39
39
|
|
|
@@ -59,7 +59,7 @@ handler.start()
|
|
|
59
59
|
|
|
60
60
|
## Additional Info
|
|
61
61
|
|
|
62
|
-
- You can
|
|
62
|
+
- You can provide a valid logger `logger=logger` to the `InputHandler` to enable logging (this will be removed soon)
|
|
63
63
|
- You can provide the `thread_mode` param to the `InputHandler` class to set if it shoud run in a thread or no.
|
|
64
64
|
(If you are using the `cli-ih` module on its own without any other background task set `thread_mode=False` to false)
|
|
65
65
|
- You can also provide a `cursor` param to the `InputHandler` class to set the cli cursor (default cusor is empty)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
cli_ih/Input_Handler.py,sha256=INlPvqlHHzN2tEDj4WUtztd2VkZZjT9FloGNSdQKc1Y,6876
|
|
2
|
+
cli_ih/__init__.py,sha256=X1CBDfeflUjcXik3rHCo-YLrIDe6EsH2ShnK57DDRYc,210
|
|
3
|
+
cli_ih-0.6.0.2.1.dist-info/METADATA,sha256=sztmZuw7GXAIvi-VSPXlO8SbEch9fdok1LKScvyRvik,2241
|
|
4
|
+
cli_ih-0.6.0.2.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
5
|
+
cli_ih-0.6.0.2.1.dist-info/top_level.txt,sha256=Ve1CRLNXhPyPSkpN0xLu26roh30LQCpNzkF61BZYfk0,7
|
|
6
|
+
cli_ih-0.6.0.2.1.dist-info/RECORD,,
|
cli_ih-0.6.0.1.dist-info/RECORD
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
cli_ih/Input_Handler.py,sha256=BvL8xAbLswSyUdTTHk-CBSxVFKfa7a5D5CC0Mwn_JEw,6578
|
|
2
|
-
cli_ih/__init__.py,sha256=X1CBDfeflUjcXik3rHCo-YLrIDe6EsH2ShnK57DDRYc,210
|
|
3
|
-
cli_ih-0.6.0.1.dist-info/METADATA,sha256=z-VPeMVnYZ9m6_rcgsKAX_FLsMrfBOd-QcFzwFlC8_I,2156
|
|
4
|
-
cli_ih-0.6.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
5
|
-
cli_ih-0.6.0.1.dist-info/top_level.txt,sha256=Ve1CRLNXhPyPSkpN0xLu26roh30LQCpNzkF61BZYfk0,7
|
|
6
|
-
cli_ih-0.6.0.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|