Implement command to manage defaults

This commit is contained in:
Mark Veidemanis 2017-12-26 14:25:36 +00:00
parent 740fc0034c
commit 34d5468672
3 changed files with 65 additions and 1 deletions

View File

@ -7,7 +7,6 @@
"UsePassword": true,
"ConnectOnCreate": false,
"HighlightNotifications": true,
"Debugger": false,
"DistEnabled": true,
"SendDistOutput": false,
"Password": "s",

View File

@ -4,6 +4,7 @@
"add": "add <name> [<address>] [<port>] [<ssl|plain>] [<nickname>]",
"del": "del <name>",
"mod": "mod <name> [<key>] [<value>]",
"default": "default [<key>] [<value>]",
"get": "get <name> <variable>",
"key": "key <master|show|add|del|except|unexcept|showexcept|monitor> [<name>] [<target>] [<key>] [<on|off>]",
"who": "who <nick>",

View File

@ -985,6 +985,70 @@ class Helper(object):
else:
incUsage("del")
return
elif cmd == "default":
toUnset = False
if length == 1:
optionMap = ["Viewing defaults"]
for i in config["Default"].keys():
optionMap.append("%s: %s" % (i, config["Default"][i]))
info("\n".join(optionMap))
return
elif length == 2:
if not spl[1] in config["Default"].keys():
failure("No such key: %s" % spl[1])
return
info("%s: %s" % (spl[1], config["Default"][spl[1]]))
return
elif length == 3:
if not spl[1] in config["Default"].keys():
failure("No such key: %s" % spl[1])
return
if spl[2].lower() in ["none", "nil"]:
spl[2] = None
toUnset = True
if spl[1] in ["port", "timeout"]:
try:
int(spl[2])
except:
failure("Value must be an integer, not %s" % spl[2])
return
if spl[1] == "protocol":
if not toUnset:
if not spl[2] in ["ssl", "plain"]:
failure("Protocol must be ssl or plain, not %s" % spl[2])
return
if spl[2] == config["Default"][spl[1]]:
failure("Value already exists: %s" % spl[2])
return
if spl[1] == "authtype":
if not toUnset:
if not spl[2] in ["sp", "ns"]:
failure("Authtype must be sp or ns, not %s" % spl[2])
return
if spl[1] == "enabled":
failure("Use the ConnectOnCreate config parameter to set this")
return
if spl[1] == "autojoin":
if not toUnset:
spl[2] = spl[2].split(",")
else:
spl[2] = []
config["Default"][spl[1]] = spl[2]
self.saveConfig()
if toUnset:
success("Successfully unset key %s" % spl[1])
else:
success("Successfully set key %s to %s" % (spl[1], spl[2]))
return
else:
incUsage("default")
return
elif cmd == "mod":
toUnset = False