diff -r b994444f7dee -r ab97727357a4 VirtualMailManager/cli/subcommands.py --- a/VirtualMailManager/cli/subcommands.py Sun Sep 02 20:18:16 2012 +0000 +++ b/VirtualMailManager/cli/subcommands.py Sun Sep 02 21:01:40 2012 +0000 @@ -16,6 +16,7 @@ from VirtualMailManager import ENCODING from VirtualMailManager.cli import get_winsize, prog, w_err, w_std +from VirtualMailManager.cli.clihelp import help_msgs from VirtualMailManager.common import human_size, size_in_bytes, \ version_str, format_domain_default from VirtualMailManager.constants import __copyright__, __date__, \ @@ -48,6 +49,10 @@ class Command(object): """Container class for command information.""" __slots__ = ('name', 'alias', 'func', 'args', 'descr') + FMT_HLP_USAGE = """ +usage: %(prog)s %(name)s %(args)s + %(prog)s %(alias)s %(args)s +""" def __init__(self, name, alias, func, args, descr): """Create a new Command instance. @@ -76,6 +81,26 @@ """the command's usage info.""" return u'%s %s %s' % (prog, self.name, self.args) + def help_(self): + """Print the Command's help message to stdout.""" + old_ii = txt_wrpr.initial_indent + old_si = txt_wrpr.subsequent_indent + + txt_wrpr.subsequent_indent = (len(self.name) + 2) * ' ' + w_std(txt_wrpr.fill('%s: %s' % (self.name, self.descr))) + + info = Command.FMT_HLP_USAGE % dict(alias=self.alias, args=self.args, + name=self.name, prog=prog) + w_std(info) + + txt_wrpr.initial_indent = txt_wrpr.subsequent_indent = ' ' + try: + [w_std(txt_wrpr.fill(_(para)) + '\n') for para + in help_msgs[self.name]] + except KeyError: + w_err(1, _(u"Subcommand '%s' is not yet documented." % self.name), + 'see also: vmm(1)') + class RunContext(object): """Contains all information necessary to run a subcommand.""" @@ -445,8 +470,8 @@ else: usage(INVALID_ARGUMENT, _(u"Unknown help topic: '%s'") % ctx.args[2], ctx.scmd) - # FIXME - w_err(1, "'help %s' not yet implemented." % topic, 'see also: vmm(1)') + if topic != u'help': + return cmd_map[topic].help_() old_ii = txt_wrpr.initial_indent old_si = txt_wrpr.subsequent_indent