Support multiple "usage" values in commands.py
This commit is contained in:
parent
857761a653
commit
ec72787f86
1 changed files with 15 additions and 8 deletions
|
@ -154,10 +154,10 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
min_args = hook.kwargs.get("min_args")
|
min_args = hook.kwargs.get("min_args")
|
||||||
if min_args and len(args_split) < min_args:
|
if min_args and len(args_split) < min_args:
|
||||||
usage = self._get_usage(hook)
|
usage = self._get_usage(hook, command)
|
||||||
if usage:
|
if usage:
|
||||||
stderr.write("Not enough arguments, usage: %s %s" % (
|
stderr.write("Not enough arguments, usage: %s" %
|
||||||
command, usage)).send()
|
usage).send()
|
||||||
else:
|
else:
|
||||||
stderr.write("Not enough arguments (minimum: %d)" %
|
stderr.write("Not enough arguments (minimum: %d)" %
|
||||||
min_args).send()
|
min_args).send()
|
||||||
|
@ -203,8 +203,15 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
def _get_help(self, hook):
|
def _get_help(self, hook):
|
||||||
return hook.get_kwarg("help", None) or hook.docstring.description
|
return hook.get_kwarg("help", None) or hook.docstring.description
|
||||||
def _get_usage(self, hook):
|
def _get_usage(self, hook, command):
|
||||||
return hook.get_kwarg("usage", None)
|
usage = hook.get_kwarg("usage", None)
|
||||||
|
is not usage:
|
||||||
|
usages = hook.docstring.var_items.get("usage", None)
|
||||||
|
if usages:
|
||||||
|
return " | ".join(
|
||||||
|
"%s %s" % (command, usage) for usage in usages)
|
||||||
|
return usage
|
||||||
|
|
||||||
def _get_prefix(self, hook):
|
def _get_prefix(self, hook):
|
||||||
return hook.get_kwarg("prefix", None)
|
return hook.get_kwarg("prefix", None)
|
||||||
def _get_alias_of(self, hook):
|
def _get_alias_of(self, hook):
|
||||||
|
@ -255,12 +262,12 @@ class Module(ModuleManager.BaseModule):
|
||||||
command = event["args_split"][0].lower()
|
command = event["args_split"][0].lower()
|
||||||
if command in self.events.on("received").on(
|
if command in self.events.on("received").on(
|
||||||
"command").get_children():
|
"command").get_children():
|
||||||
|
command_str = "%s%s" % (command_prefix, command)
|
||||||
hooks = self.events.on("received.command").on(command).get_hooks()
|
hooks = self.events.on("received.command").on(command).get_hooks()
|
||||||
usage = self._get_usage(hooks[0])
|
usage = self._get_usage(hooks[0], command_str)
|
||||||
|
|
||||||
if usage:
|
if usage:
|
||||||
event["stdout"].write("Usage: %s%s %s" % (command_prefix,
|
event["stdout"].write("Usage: %s" % usage))
|
||||||
command, usage))
|
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("No usage help available for %s" % command)
|
event["stderr"].write("No usage help available for %s" % command)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue