Show example usage when a user does not provide a setting value
This commit is contained in:
parent
13a878cc17
commit
fef97bfcd8
1 changed files with 18 additions and 13 deletions
|
@ -41,11 +41,10 @@ class Module(ModuleManager.BaseModule):
|
||||||
settings = self.exports.get_all(category)
|
settings = self.exports.get_all(category)
|
||||||
settings_dict = {setting["setting"]: setting for setting in settings}
|
settings_dict = {setting["setting"]: setting for setting in settings}
|
||||||
|
|
||||||
if len(args) > 1:
|
setting = args[0].lower()
|
||||||
setting = args[0].lower()
|
if setting in settings_dict:
|
||||||
if setting in settings_dict:
|
setting_options = settings_dict[setting]
|
||||||
setting_options = settings_dict[setting]
|
if len(args) > 1:
|
||||||
|
|
||||||
value = " ".join(args[1:])
|
value = " ".join(args[1:])
|
||||||
value = setting_options.get("validate", lambda x: x)(value)
|
value = setting_options.get("validate", lambda x: x)(value)
|
||||||
|
|
||||||
|
@ -58,16 +57,22 @@ class Module(ModuleManager.BaseModule):
|
||||||
event["stdout"].write("Saved setting")
|
event["stdout"].write("Saved setting")
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("Invalid value")
|
event["stderr"].write("Invalid value")
|
||||||
|
elif len(args) == 1:
|
||||||
|
example = setting_options.get("example", None)
|
||||||
|
if example:
|
||||||
|
event["stderr"].write("Please provide a value, e.g. %s"
|
||||||
|
% example)
|
||||||
|
else:
|
||||||
|
event["stderr"].write("Please provide a value")
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("Unknown setting")
|
shown_settings = [key for key, value in settings_dict.items()
|
||||||
elif len(args) == 1:
|
|
||||||
event["stderr"].write("Please provide a value")
|
|
||||||
else:
|
|
||||||
shown_settings = [key for key, value in settings_dict.items()
|
|
||||||
if not value.get("hidden", False)]
|
if not value.get("hidden", False)]
|
||||||
shown_settings = sorted(shown_settings)
|
shown_settings = sorted(shown_settings)
|
||||||
event["stdout"].write("Available settings: %s" % (
|
event["stdout"].write("Available settings: %s" % (
|
||||||
", ".join(shown_settings)))
|
", ".join(shown_settings)))
|
||||||
|
else:
|
||||||
|
event["stderr"].write("Unknown setting")
|
||||||
|
|
||||||
|
|
||||||
@utils.hook("received.command.set", help="Set a specified user setting")
|
@utils.hook("received.command.set", help="Set a specified user setting")
|
||||||
def set(self, event):
|
def set(self, event):
|
||||||
|
|
Loading…
Reference in a new issue