summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mailman/commands/cli_lists.py12
-rw-r--r--src/mailman/commands/docs/create.rst20
-rw-r--r--src/mailman/commands/tests/test_create.py31
-rw-r--r--src/mailman/docs/NEWS.rst8
-rw-r--r--src/mailman/interfaces/command.py4
5 files changed, 46 insertions, 29 deletions
diff --git a/src/mailman/commands/cli_lists.py b/src/mailman/commands/cli_lists.py
index 035dce898..3f31fda76 100644
--- a/src/mailman/commands/cli_lists.py
+++ b/src/mailman/commands/cli_lists.py
@@ -156,17 +156,19 @@ class Create:
domain_options = command_parser.add_mutually_exclusive_group()
domain_options.add_argument(
'-d', '--domain',
+ dest='domain',
default=True, action='store_true',
help=_("""\
- Register the mailing list's domain if not yet registered."""),
- dest='domain')
+ Register the mailing list's domain if not yet registered. This is
+ the default behavior, but these options are provided for backward
+ compatibility."""))
domain_options.add_argument(
'-D', '--no-domain',
+ dest='domain',
default=False, action='store_false',
help=_("""\
- Do not register the mailing list's domain if not already registered."""),
- dest='domain')
-
+ Do not register the mailing list's domain if not already
+ registered."""))
# Required positional argument.
command_parser.add_argument(
'listname', metavar='LISTNAME', nargs=1,
diff --git a/src/mailman/commands/docs/create.rst b/src/mailman/commands/docs/create.rst
index aee6b1f05..701a51a08 100644
--- a/src/mailman/commands/docs/create.rst
+++ b/src/mailman/commands/docs/create.rst
@@ -8,7 +8,7 @@ A system administrator can create mailing lists by the command line.
... language = None
... owners = []
... quiet = False
- ... domain = None
+ ... domain = True
... listname = None
... notify = False
@@ -22,20 +22,17 @@ You cannot create a mailing list in an unknown domain.
... print(message)
>>> command.parser = FakeParser()
+ >>> FakeArgs.domain = False
>>> FakeArgs.listname = ['test@example.xx']
>>> command.process(FakeArgs)
Undefined domain: example.xx
-The ``-d`` or ``--domain`` option is used to tell Mailman to auto-register the
-domain. Both the mailing list and domain will be created.
+By default, Mailman will create the domain if it doesn't exist.
>>> FakeArgs.domain = True
>>> command.process(FakeArgs)
Created mailing list: test@example.xx
-This is the default behaviour. Even if you do not specify any option,
-Mailman will itself make the domain if it doesn't exist.
-
Now both the domain and the mailing list exist in the database.
::
@@ -49,9 +46,10 @@ Now both the domain and the mailing list exist in the database.
>>> getUtility(IDomainManager).get('example.xx')
<Domain example.xx, base_url: http://example.xx>
-You can also create mailing lists in existing domains by using the
-``-D`` or ``--no-domain`` flag.
-::
+You can prevent the creation of the domain in existing domains by using the
+``-D`` or ``--no-domain`` flag. Although the ``--no-domain`` flag is not
+required when domain already exists it can be used to force an error when
+domain doesn't exist.
>>> FakeArgs.domain = False
>>> FakeArgs.listname = ['test1@example.com']
@@ -61,10 +59,6 @@ You can also create mailing lists in existing domains by using the
>>> list_manager.get('test1@example.com')
<mailing list "test1@example.com" at ...>
-Although the ``--no-domain`` flag is not required when domain already
-exists it can be used to error out when domain doesn't exist. In such
-case, Mailman will give an error message.
-
The command can also operate quietly.
::
diff --git a/src/mailman/commands/tests/test_create.py b/src/mailman/commands/tests/test_create.py
index 83a4dcb33..97a8d895e 100644
--- a/src/mailman/commands/tests/test_create.py
+++ b/src/mailman/commands/tests/test_create.py
@@ -56,8 +56,7 @@ class TestCreate(unittest.TestCase):
def setUp(self):
self.command = Create()
- self.parser = ArgumentParser()
- self.command.add(FakeParser(), self.parser)
+ self.command.parser = FakeParser()
self.args = FakeArgs()
def test_cannot_create_duplicate_list(self):
@@ -84,7 +83,6 @@ class TestCreate(unittest.TestCase):
def test_invalid_owner_addresses(self):
# Cannot create a list with invalid owner addresses. LP: #778687
self.args.listname = ['test@example.com']
- self.args.domain = True
self.args.owners = ['main=True']
try:
self.command.process(self.args)
@@ -94,16 +92,31 @@ class TestCreate(unittest.TestCase):
'Illegal owner addresses: main=True')
def test_without_domain_option(self):
- # Domain should be created if option not specified.
- args = self.parser.parse_args('test@list.org'.split())
+ # The domain will be created if no domain options are specified.
+ parser = ArgumentParser()
+ self.command.add(FakeParser(), parser)
+ args = parser.parse_args('test@example.org'.split())
self.assertTrue(args.domain)
def test_with_domain_option(self):
- # Domain should be created if option given.
- args = self.parser.parse_args('-d test@list.org'.split())
+ # The domain will be created if -d is given explicitly.
+ parser = ArgumentParser()
+ self.command.add(FakeParser(), parser)
+ args = parser.parse_args('-d test@example.org'.split())
self.assertTrue(args.domain)
def test_with_nodomain_option(self):
- # Domain should not be created if --no-domain is given.
- args = self.parser.parse_args('-D test@list.net'.split())
+ # The domain will not be created if --no-domain is given.
+ parser = ArgumentParser()
+ self.command.add(FakeParser(), parser)
+ args = parser.parse_args('-D test@example.net'.split())
self.assertFalse(args.domain)
+
+ def test_error_when_not_creating_domain(self):
+ self.args.domain = False
+ self.args.listname = ['test@example.org']
+ with self.assertRaises(SystemExit) as cm:
+ self.command.process(self.args)
+ self.assertEqual(cm.exception.code, 1)
+ self.assertEqual(self.command.parser.message,
+ 'Undefined domain: example.org')
diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst
index baf34413b..79adfae43 100644
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -84,6 +84,14 @@ Configuration
* The default languages from Mailman 2.1 have been ported over. Given by
Aurélien Bompard.
+Command line
+------------
+ * ``mailman create <listname@dom.ain>`` will now create missing domains
+ by default. The ``-d``/``--domain`` option is kept for backward
+ compatibility, but now there is a ``-D``/``--no-domain`` option to prevent
+ missing domains from being create, forcing an error in those cases.
+ Given by Gurkirpal Singh. (Closes #39)
+
Interfaces
----------
* Implement reasons for why a message is being held for moderator approval.
diff --git a/src/mailman/interfaces/command.py b/src/mailman/interfaces/command.py
index 5dd248ff4..9ccb9a0f4 100644
--- a/src/mailman/interfaces/command.py
+++ b/src/mailman/interfaces/command.py
@@ -79,8 +79,8 @@ class ICLISubCommand(Interface):
:param parser: The argument parser.
:type parser: `argparse.ArgumentParser`
- :param subparser: The command subparser.
- :type subparser: `argparse.ArgumentParser`
+ :param command_parser: The command subparser.
+ :type command_parser: `argparse.ArgumentParser`
"""
def process(args):