Apply the correct number of arguments to a function

This commit is contained in:
Nick Chambers 2022-08-20 04:54:41 -05:00
parent 5de4e9496a
commit 0540890cb9
1 changed files with 6 additions and 3 deletions

View File

@ -38,6 +38,8 @@ class Command:
self.needs_api_key = True
self.default = "help"
# FIXME: add support for argument parsing
self.init()
if self.needs_api_key and api_key is None:
@ -48,12 +50,13 @@ class Command:
def exec_shortcut(self, shortcut, *args):
fn = self.find(shortcut)
sig = inspect.signature(fn)
parity = len(sig.parameters)
if len(args) < len(sig.parameters):
if len(args) < parity:
name = fn.__name__[len(self.FTR_PRFX):].lower()
raise NotEnoughArgs(name, len(sig.parameters) - len(args))
raise NotEnoughArgs(name, parity - len(args))
data = fn(*args)
data = fn(*args[:parity])
# FIXME: Let functions choose the output format. This will allow help
# functions to still return a rendering.