mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-10 12:59:22 +01:00
Update to use a help method instead of a help string. Allows sub-classes of
Group/Value to define their own help method.
This commit is contained in:
parent
b9db0330e4
commit
9291c56e3f
@ -240,7 +240,7 @@ class Config(callbacks.Privmsg):
|
||||
name = self._canonicalizeName(name)
|
||||
wrapper = getWrapper(name)
|
||||
if hasattr(wrapper, 'help'):
|
||||
s = wrapper.help
|
||||
s = wrapper.help()
|
||||
if s:
|
||||
if hasattr(wrapper, 'value') and not wrapper._private:
|
||||
s += ' (Current value: %s)' % wrapper
|
||||
@ -249,7 +249,6 @@ class Config(callbacks.Privmsg):
|
||||
irc.reply('That configuration group exists, but seems to have '
|
||||
'no help. Try "config list %s" to see if it has '
|
||||
'any children values.')
|
||||
|
||||
else:
|
||||
irc.error('%s has no help.' % name)
|
||||
|
||||
|
@ -80,10 +80,10 @@ def close(registry, filename, annotated=True, helpOnceOnly=False):
|
||||
helpCache = sets.Set()
|
||||
fd = utils.transactionalFile(filename)
|
||||
for (name, value) in registry.getValues(getChildren=True):
|
||||
if annotated and hasattr(value,'help') and value.help:
|
||||
if not helpOnceOnly or value.help not in helpCache:
|
||||
helpCache.add(value.help)
|
||||
lines = textwrap.wrap(value.help)
|
||||
if annotated and hasattr(value,'_help') and value._help:
|
||||
if not helpOnceOnly or value._help not in helpCache:
|
||||
helpCache.add(value._help)
|
||||
lines = textwrap.wrap(value._help)
|
||||
for (i, line) in enumerate(lines):
|
||||
lines[i] = '# %s\n' % line
|
||||
lines.insert(0, '###\n')
|
||||
@ -136,7 +136,7 @@ class Group(object):
|
||||
"""A group; it doesn't hold a value unless handled by a subclass."""
|
||||
def __init__(self, help='',
|
||||
supplyDefault=False, orderAlphabetically=False):
|
||||
self.help = help
|
||||
self._help = help
|
||||
self._name = 'unset'
|
||||
self._added = []
|
||||
self._children = utils.InsensitivePreservingDict()
|
||||
@ -163,11 +163,11 @@ class Group(object):
|
||||
raise NonExistentRegistryEntry, s
|
||||
|
||||
def __makeChild(self, attr, s):
|
||||
v = self.__class__(self._default, self.help)
|
||||
v = self.__class__(self._default, self._help)
|
||||
v.set(s)
|
||||
v.__class__ = self.X
|
||||
v._supplyDefault = False
|
||||
v.help = '' # Clear this so it doesn't print a bazillion times.
|
||||
v._help = '' # Clear this so it doesn't print a bazillion times.
|
||||
self.register(attr, v)
|
||||
return v
|
||||
|
||||
@ -179,6 +179,9 @@ class Group(object):
|
||||
else:
|
||||
self.__nonExistentEntry(attr)
|
||||
|
||||
def help(self):
|
||||
return self._help
|
||||
|
||||
def get(self, attr):
|
||||
# Not getattr(self, attr) because some nodes might have groups that
|
||||
# are named the same as their methods.
|
||||
@ -270,7 +273,7 @@ class Value(Group):
|
||||
self._default = default
|
||||
self._private = private
|
||||
self.showDefault = showDefault
|
||||
self.help = utils.normalizeWhitespace(help.strip())
|
||||
self._help = utils.normalizeWhitespace(help.strip())
|
||||
if setDefault:
|
||||
self.setValue(default)
|
||||
|
||||
@ -415,6 +418,11 @@ class OnlySomeStrings(String):
|
||||
self.__parent = super(OnlySomeStrings, self)
|
||||
self.__parent.__init__(*args, **kwargs)
|
||||
|
||||
def help(self):
|
||||
strings = [s for s in self.validStrings if s]
|
||||
return '%s Valid strings: %s.' % \
|
||||
(self._help, utils.commaAndify(strings))
|
||||
|
||||
def error(self):
|
||||
raise InvalidRegistryValue, \
|
||||
'That is not a valid value. Valid values include %s.' % \
|
||||
|
Loading…
Reference in New Issue
Block a user