mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
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:
@@ -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.
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.")
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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."
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user