management: Use required kwargs in add_realm_args.

This makes management commands more readable, since one doesn't need
to know details of how the library works to read based code.
This commit is contained in:
Tim Abbott
2021-05-10 12:29:25 -07:00
parent 55f4996f16
commit 2c01354569
21 changed files with 21 additions and 21 deletions

View File

@@ -45,7 +45,7 @@ class ZulipBaseCommand(BaseCommand):
return parser
def add_realm_args(
self, parser: ArgumentParser, required: bool = False, help: Optional[str] = None
self, parser: ArgumentParser, *, required: bool = False, help: Optional[str] = None
) -> None:
if help is None:
help = """The numeric or string ID (subdomain) of the Zulip organization to modify.

View File

@@ -10,7 +10,7 @@ class Command(ZulipBaseCommand):
help = """Add some or all users in a realm to a set of streams."""
def add_arguments(self, parser: CommandParser) -> None:
self.add_realm_args(parser, True)
self.add_realm_args(parser, required=True)
self.add_user_list_args(parser, all_users_help="Add all users in realm to these streams.")
parser.add_argument(

View File

@@ -16,7 +16,7 @@ class Command(ZulipBaseCommand):
metavar="<data file>",
help="file containing rows of the form <email>,<desired name>",
)
self.add_realm_args(parser, True)
self.add_realm_args(parser, required=True)
def handle(self, *args: Any, **options: str) -> None:
data_file = options["data_file"]

View File

@@ -40,7 +40,7 @@ ONLY perform this on customer request from an authorized person.
action="store_false",
help="Remove can_forge_sender or can_create_users permission.",
)
self.add_realm_args(parser, True)
self.add_realm_args(parser, required=True)
def handle(self, *args: Any, **options: Any) -> None:
email = options["email"]

View File

@@ -14,7 +14,7 @@ Create default stream groups which the users can choose during sign up.
"""
def add_arguments(self, parser: ArgumentParser) -> None:
self.add_realm_args(parser, True)
self.add_realm_args(parser, required=True)
parser.add_argument(
"-n",

View File

@@ -12,7 +12,7 @@ This should be used for TESTING only, unless you understand the limitations of
the command."""
def add_arguments(self, parser: ArgumentParser) -> None:
self.add_realm_args(parser, True, "realm in which to create the stream")
self.add_realm_args(parser, required=True, help="realm in which to create the stream")
parser.add_argument("stream_name", metavar="<stream name>", help="name of stream to create")
def handle(self, *args: Any, **options: str) -> None:

View File

@@ -53,7 +53,7 @@ Omit both <email> and <full name> for interactive user creation.
help="full name of new user",
)
self.add_realm_args(
parser, True, "The name of the existing realm to which to add the user."
parser, required=True, help="The name of the existing realm to which to add the user."
)
def handle(self, *args: Any, **options: Any) -> None:

View File

@@ -12,7 +12,7 @@ class Command(ZulipBaseCommand):
parser.add_argument(
"--redirect_url", metavar="<redirect_url>", help="URL to which the realm has moved"
)
self.add_realm_args(parser, True)
self.add_realm_args(parser, required=True)
def handle(self, *args: Any, **options: str) -> None:
realm = self.get_realm(options)

View File

@@ -12,7 +12,7 @@ class Command(ZulipBaseCommand):
realms used for testing; consider using deactivate_realm instead."""
def add_arguments(self, parser: ArgumentParser) -> None:
self.add_realm_args(parser, True)
self.add_realm_args(parser, required=True)
def handle(self, *args: Any, **options: str) -> None:
realm = self.get_realm(options)

View File

@@ -13,7 +13,7 @@ class Command(ZulipBaseCommand):
def add_arguments(self, parser: CommandParser) -> None:
default_cutoff = time.time() - 60 * 60 * 24 * 30 # 30 days.
self.add_realm_args(parser, True)
self.add_realm_args(parser, required=True)
parser.add_argument(
"--since",
type=int,

View File

@@ -35,7 +35,7 @@ Example: ./manage.py realm_filters --realm=zulip --op=show
nargs="?",
help="format string to substitute",
)
self.add_realm_args(parser, True)
self.add_realm_args(parser, required=True)
def handle(self, *args: Any, **options: str) -> None:
realm = self.get_realm(options)

View File

@@ -110,7 +110,7 @@ class Command(ZulipBaseCommand):
action="store_true",
help="Automatically delete the local tarball after a successful export",
)
self.add_realm_args(parser, True)
self.add_realm_args(parser, required=True)
def handle(self, *args: Any, **options: Any) -> None:
realm = self.get_realm(options)

View File

@@ -24,7 +24,7 @@ class Command(ZulipBaseCommand):
nargs="*",
help="email of users to generate an activation link for",
)
self.add_realm_args(parser, True)
self.add_realm_args(parser, required=True)
def handle(self, *args: Any, **options: Any) -> None:
duplicates = False

View File

@@ -10,7 +10,7 @@ class Command(ZulipBaseCommand):
help = "Generates invite link that can be used for inviting multiple users"
def add_arguments(self, parser: ArgumentParser) -> None:
self.add_realm_args(parser, True)
self.add_realm_args(parser, required=True)
parser.add_argument("-s", "--streams", help="A comma-separated list of stream names.")

View File

@@ -29,7 +29,7 @@ class Command(ZulipBaseCommand):
parser.add_argument(
"stream_to_destroy", help="name of stream to merge into the stream being kept"
)
self.add_realm_args(parser, True)
self.add_realm_args(parser, required=True)
def handle(self, *args: Any, **options: str) -> None:
realm = self.get_realm(options)

View File

@@ -9,7 +9,7 @@ class Command(ZulipBaseCommand):
help = """Script to reactivate a deactivated realm."""
def add_arguments(self, parser: ArgumentParser) -> None:
self.add_realm_args(parser, True)
self.add_realm_args(parser, required=True)
def handle(self, *args: Any, **options: str) -> None:
realm = self.get_realm(options)

View File

@@ -21,7 +21,7 @@ class Command(ZulipBaseCommand):
"--allow-subdomains", action="store_true", help="Whether subdomains are allowed or not."
)
parser.add_argument("domain", metavar="<domain>", nargs="?", help="domain to add or remove")
self.add_realm_args(parser, True)
self.add_realm_args(parser, required=True)
def handle(self, *args: Any, **options: str) -> None:
realm = self.get_realm(options)

View File

@@ -13,7 +13,7 @@ class Command(ZulipBaseCommand):
def add_arguments(self, parser: CommandParser) -> None:
parser.add_argument("-s", "--stream", required=True, help="A stream name.")
self.add_realm_args(parser, True)
self.add_realm_args(parser, required=True)
self.add_user_list_args(
parser, all_users_help="Remove all users in realm from this stream."
)

View File

@@ -14,7 +14,7 @@ class Command(ZulipBaseCommand):
parser.add_argument(
"new_name", metavar="<new name>", help="new name to rename the stream to"
)
self.add_realm_args(parser, True)
self.add_realm_args(parser, required=True)
def handle(self, *args: Any, **options: str) -> None:
realm = self.get_realm(options)

View File

@@ -9,7 +9,7 @@ class Command(ZulipBaseCommand):
help = """Script to scrub a deactivated realm."""
def add_arguments(self, parser: ArgumentParser) -> None:
self.add_realm_args(parser, True)
self.add_realm_args(parser, required=True)
def handle(self, *args: Any, **options: str) -> None:
realm = self.get_realm(options)

View File

@@ -9,7 +9,7 @@ class Command(ZulipBaseCommand):
help = """Sends realm reactivation email to admins"""
def add_arguments(self, parser: ArgumentParser) -> None:
self.add_realm_args(parser, True)
self.add_realm_args(parser, required=True)
def handle(self, *args: Any, **options: str) -> None:
realm = self.get_realm(options)