Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

upgrade-zulip-from-git: Surface stage-3 options in --help.

Aman Agrawald37287f6631e
diff --git a/scripts/lib/upgrade-zulip-from-git b/scripts/lib/upgrade-zulip-from-git
index d49416ac57c..cee69f86dbd 100755
--- a/scripts/lib/upgrade-zulip-from-git
+++ b/scripts/lib/upgrade-zulip-from-git
@@ -22,6 +22,7 @@ from scripts.lib.zulip_tools import (
overwrite_symlink,
release_deployment_lock,
su_to_zulip,
+ upgrade_script_arg_parser,
)
config_file = get_config_file()
@@ -38,7 +39,7 @@ os.umask(0o22)
logging.Formatter.converter = time.gmtime
logging.basicConfig(format="%(asctime)s upgrade-zulip-from-git: %(message)s", level=logging.INFO)
-parser = argparse.ArgumentParser()
+parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("refname", help="Git reference, e.g. a branch, tag, or commit ID.")
git_ref = parser.add_mutually_exclusive_group()
git_ref.add_argument(
@@ -49,6 +50,14 @@ git_ref.add_argument(
action="store_true",
help="Provided branch name has been pushed directly to /srv/zulip.git already",
)
+
+# Any unknown options are passed through verbatim to upgrade-zulip-stage-2
+# and on to upgrade-zulip-stage-3. To make those passthrough options
+# discoverable, when the user runs --help we show a combined help that
+# also documents the stage-3 options.
+if {"-h", "--help"} & set(sys.argv[1:]):
+ argparse.ArgumentParser(parents=[parser, upgrade_script_arg_parser()]).parse_args(["--help"])
+
args, extra_options = parser.parse_known_args()
refname = args.refname
diff --git a/scripts/lib/upgrade-zulip-stage-3 b/scripts/lib/upgrade-zulip-stage-3
index 6e3cf99dc95..c6eb01af4be 100755
--- a/scripts/lib/upgrade-zulip-stage-3
+++ b/scripts/lib/upgrade-zulip-stage-3
@@ -26,8 +26,8 @@ from scripts.lib.zulip_tools import (
get_config,
get_config_file,
parse_version_from,
- start_arg_parser,
su_to_zulip,
+ upgrade_script_arg_parser,
)
assert_running_as_root()
@@ -41,36 +41,11 @@ logging.basicConfig(format="%(asctime)s upgrade-zulip-stage-3: %(message)s", lev
# make sure we have appropriate file permissions
os.umask(0o22)
-restart_parser = start_arg_parser(action="restart", add_help=False)
-
-parser = argparse.ArgumentParser(parents=[restart_parser])
+parser = argparse.ArgumentParser(parents=[upgrade_script_arg_parser()])
parser.add_argument("deploy_path", metavar="deploy_path", help="Path to deployment directory")
-parser.add_argument(
- "--skip-restart",
- action="store_true",
- help="Configure, but do not restart into, the new version; aborts if any system-wide changes would happen.",
-)
-parser.add_argument("--skip-puppet", action="store_true", help="Skip doing puppet/apt upgrades.")
-parser.add_argument("--skip-migrations", action="store_true", help="Skip doing migrations.")
-parser.add_argument(
- "--skip-downgrade-check",
- action="store_true",
- help="Skip the safety check to prevent database downgrades.",
-)
parser.add_argument(
"--from-git", action="store_true", help="Upgrading from git, so run update-prod-static."
)
-parser.add_argument(
- "--ignore-static-assets",
- action="store_true",
- help="Do not attempt to copy/manage static assets.",
-)
-parser.add_argument(
- "--skip-purge-old-deployments", action="store_true", help="Skip purging old deployments."
-)
-parser.add_argument(
- "--audit-fts-indexes", action="store_true", help="Audit and fix full text search indexes."
-)
args = parser.parse_args()
if args.skip_restart:
diff --git a/scripts/lib/zulip_tools.py b/scripts/lib/zulip_tools.py
index cf9813696a5..012210d08a9 100755
--- a/scripts/lib/zulip_tools.py
+++ b/scripts/lib/zulip_tools.py
@@ -682,6 +682,48 @@ def start_arg_parser(action: str, add_help: bool = False) -> argparse.ArgumentPa
return parser
+def upgrade_script_arg_parser() -> argparse.ArgumentParser:
+ """Options shared by upgrade-zulip-stage-3 and its wrapper scripts.
+
+ Wrappers like upgrade-zulip-from-git use this as a parent parser so
+ that --help advertises the same options stage-3 accepts, and forward
+ the parsed values through to stage-3.
+ """
+ parser = argparse.ArgumentParser(
+ add_help=False, parents=[start_arg_parser(action="restart", add_help=False)]
+ )
+ parser.add_argument(
+ "--skip-restart",
+ action="store_true",
+ help="Configure, but do not restart into, the new version; aborts if any system-wide changes would happen.",
+ )
+ parser.add_argument(
+ "--skip-puppet", action="store_true", help="Skip doing puppet/apt upgrades."
+ )
+ parser.add_argument("--skip-migrations", action="store_true", help="Skip doing migrations.")
+ parser.add_argument(
+ "--skip-downgrade-check",
+ action="store_true",
+ help="Skip the safety check to prevent database downgrades.",
+ )
+ parser.add_argument(
+ "--ignore-static-assets",
+ action="store_true",
+ help="Do not attempt to copy/manage static assets.",
+ )
+ parser.add_argument(
+ "--skip-purge-old-deployments",
+ action="store_true",
+ help="Skip purging old deployments.",
+ )
+ parser.add_argument(
+ "--audit-fts-indexes",
+ action="store_true",
+ help="Audit and fix full text search indexes.",
+ )
+ return parser
+
+
def atomic_nagios_write(
name: str,
status: Literal["ok", "warning", "critical", "unknown"],