Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

Stop serverkit update --help from updating

Juan Denisfbed88ea3582
diff --git a/scripts/test/test_cli.sh b/scripts/test/test_cli.sh
index 2f612c9d..ab5995ff 100644
--- a/scripts/test/test_cli.sh
+++ b/scripts/test/test_cli.sh
@@ -97,6 +97,45 @@ else
bad "update --branch dev forwarding broken: [$out]"
fi
+# T1c — unknown flags used to be dropped and the update ran anyway, so
+# `serverkit update --help` updated the box. Help prints usage; an unknown
+# flag fails; neither reaches the updater.
+for args in "--help" "--frobnicate"; do
+ out="$(
+ set -Eeuo pipefail
+ check_root() { :; }
+ check_installed() { :; }
+ INSTALL_DIR="$t"; VENV_DIR="$t/venv"
+ cmd_update $args 2>&1
+ )"
+ rc=$?
+ if printf '%s' "$out" | grep -q 'ARGS:'; then
+ bad "update $args ran the updater: [$out]"
+ elif ! printf '%s' "$out" | grep -q 'Usage: serverkit update'; then
+ bad "update $args printed no usage: rc=$rc out=[$out]"
+ elif [ "$args" = "--help" ] && [ "$rc" -ne 0 ]; then
+ bad "update --help exited $rc"
+ elif [ "$args" != "--help" ] && [ "$rc" -eq 0 ]; then
+ bad "update $args exited 0"
+ else
+ ok "update $args prints usage and never runs the updater (rc=$rc)"
+ fi
+done
+
+for args in "--help" "--frobnicate"; do
+ out="$( set -Eeuo pipefail; check_root() { :; }; cmd_uninstall $args 2>&1 )"
+ rc=$?
+ if printf '%s' "$out" | grep -q 'This will remove ServerKit'; then
+ bad "uninstall $args went on to the uninstall: [$out]"
+ elif [ "$args" = "--help" ] && [ "$rc" -eq 0 ]; then
+ ok "uninstall --help prints usage only"
+ elif [ "$args" != "--help" ] && [ "$rc" -ne 0 ]; then
+ ok "uninstall with an unknown flag fails (rc=$rc)"
+ else
+ bad "uninstall $args: rc=$rc out=[$out]"
+ fi
+done
+
# --------------------------------------------------------------------------
# T2 — L6: cmd_start must warn (not raw-abort) when systemctl/docker fail
# (partial installs, non-systemd boxes). cmd_stop already had these guards.
diff --git a/serverkit b/serverkit
index f3bf6579..ade58df7 100644
--- a/serverkit
+++ b/serverkit
@@ -598,6 +598,14 @@ cmd_branch() {
echo ""
}
+update_usage() {
+ echo "Usage: serverkit update [options]"
+ echo " --branch <name> Switch to specific branch (e.g., dev)"
+ echo " --release [vX.Y.Z] Update from release tarball"
+ echo " --force Force update even if already latest"
+ echo " --dry-run Show what would change without applying"
+}
+
cmd_update() {
local update_args=()
@@ -632,8 +640,16 @@ cmd_update() {
update_args+=("--dry-run")
shift
;;
+ --help|-h)
+ update_usage
+ return 0
+ ;;
*)
- shift
+ # An unknown flag used to be dropped and the update ran
+ # anyway — `update --help` updated the box.
+ print_error "Unknown option for update: $1"
+ update_usage
+ exit 1
;;
esac
done
@@ -666,7 +682,12 @@ cmd_uninstall() {
--keep-data) keep_data=1; shift ;;
--yes|-y) assume_yes=1; shift ;;
--dry-run|-n) dry_run=1; shift ;;
- *) shift ;;
+ --help|-h)
+ echo "Usage: serverkit uninstall [--purge|--delete-volumes] [--keep-data] [--yes] [--dry-run]"
+ return 0 ;;
+ *)
+ print_error "Unknown option for uninstall: $1"
+ exit 1 ;;
esac
done
@@ -810,8 +831,13 @@ cmd_cleanup_apps() {
KEEP_DB="--keep-db"
shift
;;
+ --help|-h)
+ run_cli cleanup-apps --help
+ return 0
+ ;;
*)
- shift
+ print_error "Unknown option for cleanup-apps: $1"
+ exit 1
;;
esac
done