cli-ih 0.6.0.2__py3-none-any.whl → 0.6.1.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 CHANGED
@@ -52,22 +52,25 @@ class InputHandler:
52
52
  else:
53
53
  print(f"[EXEPTION]: {msg}: {e}")
54
54
 
55
- def register_command(self, name: str, func: Callable, description: str = ""):
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.register_command(lname, func, description)
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(args)
89
+ sig = inspect.signature(func)
90
+ sig.bind(*args)
89
91
  except TypeError as e:
90
- self.__error(f"Error calling command '{name}': {e}")
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(args):
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(args):
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(args):
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.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cli_ih
3
- Version: 0.6.0.2
3
+ Version: 0.6.1.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
@@ -0,0 +1,6 @@
1
+ cli_ih/Input_Handler.py,sha256=NvmaLOBgip76tU3NN_NYKfGXi8y2X6bdeNqkM0W7Iyc,6588
2
+ cli_ih/__init__.py,sha256=X1CBDfeflUjcXik3rHCo-YLrIDe6EsH2ShnK57DDRYc,210
3
+ cli_ih-0.6.1.1.dist-info/METADATA,sha256=14APY3HexSeaVdMcH6Tyq1nZbLCDecwW9elapo66C00,2239
4
+ cli_ih-0.6.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
+ cli_ih-0.6.1.1.dist-info/top_level.txt,sha256=Ve1CRLNXhPyPSkpN0xLu26roh30LQCpNzkF61BZYfk0,7
6
+ cli_ih-0.6.1.1.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- cli_ih/Input_Handler.py,sha256=4fyKMmtKKnI-XKWPayURl-6dStZc6ucz8EfPKq9oUi4,6741
2
- cli_ih/__init__.py,sha256=X1CBDfeflUjcXik3rHCo-YLrIDe6EsH2ShnK57DDRYc,210
3
- cli_ih-0.6.0.2.dist-info/METADATA,sha256=fxJsIsURsliq08ppniBrs-FzHimQvjnPHyNSx4xv1Ko,2239
4
- cli_ih-0.6.0.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
- cli_ih-0.6.0.2.dist-info/top_level.txt,sha256=Ve1CRLNXhPyPSkpN0xLu26roh30LQCpNzkF61BZYfk0,7
6
- cli_ih-0.6.0.2.dist-info/RECORD,,