[IMP] add argument validation with usage message

Add proper argument validation at the start of upgrade.sh:
- Check that exactly 4 arguments are provided
- Display a helpful usage message with argument descriptions
- Include a concrete example command

This prevents cryptic errors when the script is called incorrectly
and provides clear guidance on expected parameters. With set -u enabled,
accessing unset positional parameters would cause an unclear error message.
This commit is contained in:
Stéphan Sainléger
2026-02-02 17:55:02 +01:00
parent 30909a3b28
commit 266842585b

View File

@@ -1,6 +1,31 @@
#!/bin/bash #!/bin/bash
set -euo pipefail set -euo pipefail
####################
# USAGE & ARGUMENTS
####################
usage() {
cat <<EOF >&2
Usage: $0 <origin_version> <final_version> <db_name> <service_name>
Arguments:
origin_version Origin Odoo version number (e.g., 12 for version 12.0)
final_version Target Odoo version number (e.g., 16 for version 16.0)
db_name Name of the database to migrate
service_name Name of the origin Odoo service (docker compose service)
Example:
$0 14 16 elabore_20241208 odoo14
EOF
exit 1
}
if [[ $# -lt 4 ]]; then
echo "ERROR: Missing arguments. Expected 4, got $#." >&2
usage
fi
#################### ####################
# GLOBAL VARIABLES # # GLOBAL VARIABLES #
#################### ####################