diff options
| author | Barry Warsaw | 2009-08-16 09:32:10 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2009-08-16 09:32:10 -0400 |
| commit | 82affb2668ec6fa2d04fe7965a4c317eb13d8fce (patch) | |
| tree | fea7c42631eda905798fedc167ff0dfe35862df3 | |
| parent | 592f3d56d2fd87cf06fdeb2bb63907a82ec172b2 (diff) | |
| download | mailman-82affb2668ec6fa2d04fe7965a4c317eb13d8fce.tar.gz mailman-82affb2668ec6fa2d04fe7965a4c317eb13d8fce.tar.zst mailman-82affb2668ec6fa2d04fe7965a4c317eb13d8fce.zip | |
| -rw-r--r-- | src/mailman/bin/mailman.py | 18 | ||||
| -rw-r--r-- | src/mailman/commands/cli_help.py | 10 | ||||
| -rw-r--r-- | src/mailman/commands/cli_info.py | 11 | ||||
| -rw-r--r-- | src/mailman/commands/cli_lists.py | 55 | ||||
| -rw-r--r-- | src/mailman/commands/cli_members.py | 46 | ||||
| -rw-r--r-- | src/mailman/interfaces/command.py | 8 |
6 files changed, 104 insertions, 44 deletions
diff --git a/src/mailman/bin/mailman.py b/src/mailman/bin/mailman.py index 7ff8310a8..c1b2931a4 100644 --- a/src/mailman/bin/mailman.py +++ b/src/mailman/bin/mailman.py @@ -60,10 +60,26 @@ def main(): # partially parse the arguments now, then initialize the system, then find # the plugins. Punt on this for now. subparser = parser.add_subparsers(title='Commands') + subcommands = [] for command_class in find_components('mailman.commands', ICLISubCommand): command = command_class() verifyObject(ICLISubCommand, command) - command.add(parser, subparser) + subcommands.append(command) + # --help should display the subcommands by alphabetical order, except that + # 'mailman help' should be first. + def sort_function(command, other): + if command.name == 'help': + return -1 + elif other.name == 'help': + return 1 + else: + return cmp(command.name, other.name) + subcommands.sort(cmp=sort_function) + for command in subcommands: + command_parser = subparser.add_parser( + command.name, help=_(command.__doc__)) + command.add(parser, command_parser) + command_parser.set_defaults(func=command.process) args = parser.parse_args() if len(args.__dict__) == 0: # No arguments or subcommands were given. diff --git a/src/mailman/commands/cli_help.py b/src/mailman/commands/cli_help.py index 4cffaaf87..8b1b7e307 100644 --- a/src/mailman/commands/cli_help.py +++ b/src/mailman/commands/cli_help.py @@ -32,16 +32,16 @@ from mailman.interfaces.command import ICLISubCommand class Help: - """The `help` subcommand.""" + # Lowercase, to match argparse's default --help text. + """show this help message and exit""" implements(ICLISubCommand) - def add(self, parser, subparser): + name = 'help' + + def add(self, parser, command_parser): """See `ICLISubCommand`.""" self.parser = parser - help_parser = subparser.add_parser( - 'help', help=('show this help message and exit')) - help_parser.set_defaults(func=self.process) def process(self, args): """See `ICLISubCommand`.""" diff --git a/src/mailman/commands/cli_info.py b/src/mailman/commands/cli_info.py index 0595c32fa..a710e3bd7 100644 --- a/src/mailman/commands/cli_info.py +++ b/src/mailman/commands/cli_info.py @@ -37,16 +37,15 @@ from mailman.version import MAILMAN_VERSION_FULL class Info: - """The `info` subcommand.""" + """Information about this Mailman instance.""" implements(ICLISubCommand) - def add(self, parser, subparser): + name = 'info' + + def add(self, parser, command_parser): """See `ICLISubCommand`.""" - info_parser = subparser.add_parser( - 'info', help=_('Information about this Mailman instance.')) - info_parser.set_defaults(func=self.process) - info_parser.add_argument( + command_parser.add_argument( '-o', '--output', action='store', help=_("""\ File to send the output to. If not given, standard output is diff --git a/src/mailman/commands/cli_lists.py b/src/mailman/commands/cli_lists.py index 9fd401949..b95d1a779 100644 --- a/src/mailman/commands/cli_lists.py +++ b/src/mailman/commands/cli_lists.py @@ -44,31 +44,30 @@ from mailman.interfaces.listmanager import ListAlreadyExistsError class Lists: - """The `lists` subcommand.""" + """List all mailing lists""" implements(ICLISubCommand) - def add(self, parser, subparser): + name = 'lists' + + def add(self, parser, command_parser): """See `ICLISubCommand`.""" - lists_parser = subparser.add_parser( - 'lists', help=_('List all mailing lists')) - lists_parser.set_defaults(func=self.process) - lists_parser.add_argument( + command_parser.add_argument( '-a', '--advertised', default=False, action='store_true', help=_( 'List only those mailing lists that are publicly advertised')) - lists_parser.add_argument( + command_parser.add_argument( '-b', '--bare', default=False, action='store_true', help=_('Show only the list name, with no description')) - lists_parser.add_argument( + command_parser.add_argument( '-d', '--domain', action='append', help=_("""\ List only those mailing lists hosted on the given domain, which must be the email host name. Multiple -d options may be given. """)) - lists_parser.add_argument( + command_parser.add_argument( '-f', '--full', default=False, action='store_true', help=_( @@ -115,22 +114,20 @@ class Lists: class Create: - """The `create` subcommand.""" + """Create a mailing list""" implements(ICLISubCommand) - def add(self, parser, subparser): + name = 'create' + + def add(self, parser, command_parser): """See `ICLISubCommand`.""" - self.parser = parser - create_parser = subparser.add_parser( - 'create', help=_('Create a mailing list')) - create_parser.set_defaults(func=self.process) - create_parser.add_argument( + command_parser.add_argument( '--language', type='unicode', metavar='CODE', help=_("""\ Set the list's preferred language to CODE, which must be a registered two letter language code.""")) - create_parser.add_argument( + command_parser.add_argument( '-o', '--owner', type='unicode', action='append', default=[], dest='owners', metavar='OWNER', help=_("""\ @@ -139,23 +136,23 @@ class Create: linked to a user. Mailman will send a confirmation message to the address, but it will also send a list creation notice to the address. More than one owner can be specified.""")) - create_parser.add_argument( + command_parser.add_argument( '-n', '--notify', default=False, action='store_true', help=_("""\ Notify the list owner by email that their mailing list has been created.""")) - create_parser.add_argument( + command_parser.add_argument( '-q', '--quiet', default=False, action='store_true', help=_('Print less output.')) - create_parser.add_argument( + command_parser.add_argument( '-d', '--domain', default=False, action='store_true', help=_("""\ Register the mailing list's domain if not yet registered.""")) # Required positional argument. - create_parser.add_argument( + command_parser.add_argument( 'listname', metavar='LISTNAME', nargs=1, help=_("""\ The 'fully qualified list name', i.e. the posting address of the @@ -221,28 +218,26 @@ class Create: class Remove: - """The `remove` subcommand.""" + """Remove a mailing list""" implements(ICLISubCommand) - def add(self, parser, subparser): + name = 'remove' + + def add(self, parser, command_parser): """See `ICLISubCommand`.""" - self.parser = parser - remove_parser = subparser.add_parser( - 'remove', help=_('Remove a mailing list')) - remove_parser.set_defaults(func=self.process) - remove_parser.add_argument( + command_parser.add_argument( '-a', '--archives', default=False, action='store_true', help=_("""\ Remove the list's archives too, or if the list has already been deleted, remove any residual archives.""")) - remove_parser.add_argument( + command_parser.add_argument( '-q', '--quiet', default=False, action='store_true', help=_('Suppress status messages')) # Required positional argument. - remove_parser.add_argument( + command_parser.add_argument( 'listname', metavar='LISTNAME', nargs=1, help=_("""\ The 'fully qualified list name', i.e. the posting address of the diff --git a/src/mailman/commands/cli_members.py b/src/mailman/commands/cli_members.py new file mode 100644 index 000000000..9d9a892d5 --- /dev/null +++ b/src/mailman/commands/cli_members.py @@ -0,0 +1,46 @@ +# Copyright (C) 2009 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. + +"""The 'members' subcommand.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'Members', + ] + + +from zope.interface import implements + +from mailman.i18n import _ +from mailman.interfaces.command import ICLISubCommand + + + +class Members: + """Manage list memberships""" + + implements(ICLISubCommand) + + name = 'members' + + def add(self, parser, command_parser): + """See `ICLISubCommand`.""" + + def process(self, args): + """See `ICLISubCommand`.""" diff --git a/src/mailman/interfaces/command.py b/src/mailman/interfaces/command.py index 074359707..7503704f0 100644 --- a/src/mailman/interfaces/command.py +++ b/src/mailman/interfaces/command.py @@ -73,12 +73,16 @@ class IEmailCommand(Interface): class ICLISubCommand(Interface): """A command line interface subcommand.""" - def add(parser, subparser): + name = Attribute('The command name; must be unique') + + __doc__ = Attribute('The command short help') + + def add(parser, command_parser): """Add the subcommand to the subparser. :param parser: The argument parser. :type parser: `argparse.ArgumentParser` - :param subparser: The argument subparser. + :param subparser: The command subparser. :type subparser: `argparse.ArgumentParser` """ |
