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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cli_ih
3
- Version: 0.6.1.1
3
+ Version: 0.6.1.2
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
@@ -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[name] = {"cmd": func, "description": description}
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
- try:
89
- sig = inspect.signature(func)
90
- sig.bind(*args)
91
- except TypeError as e:
92
- self.__warning(f"Argument error for command '{name}': {e}")
93
- return
94
- try:
95
- func(*args)
96
- except HandlerClosed as e:
97
- raise e
98
- except Exception as e:
99
- self.__exeption(f"An error occurred in command '{name}'", e)
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:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cli_ih
3
- Version: 0.6.1.1
3
+ Version: 0.6.1.2
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cli_ih"
7
- version = "0.6.1.1"
7
+ version = "0.6.1.2"
8
8
  description = "A background command handler for python's command-line interface."
9
9
  readme = "README.md"
10
10
  requires-python = ">= 3.8"
File without changes
File without changes
File without changes