Implement command to manage defaults
This commit is contained in:
64
threshold
64
threshold
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user