Files
sf-cli-wrapper/sf-deploy
reynold 39b7f11646 Update core wrapper scripts to use two-character option scheme
- Updated sf-deploy: -o → -to, -s → -sr, -d → -dr, -t → -ts
- Updated sf-dry-run: same options as sf-deploy for consistency
- Updated sf-web-open: -o → -to, -p → -pt, -U → -ur
- Updated sf-org-create: -n → -al, -d → -dd, -f → -df, -a → -st, -t → -tp
- All scripts now use manual argument parsing to support two-character options
- Help sections updated with both short and long option forms
- Maintains backward compatibility with long options
- Consistent with README documentation and two-character scheme
2025-08-28 18:28:23 +08:00

138 lines
4.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
show_help() {
cat <<'EOF'
sf-deploy — wrapper for `sf project deploy start`
USAGE:
sf-deploy -to <ORG_ALIAS_OR_USERNAME> (-sr "<src1>,<src2>[,...]" | -dr <DIRECTORY>) [-ts "<Test1>,<Test2>[,...]"]
OPTIONS:
-to, --target-org Org alias or username for --target-org
-sr, --sources Comma-separated list of --source-dir paths
-dr, --directory Single directory path to deploy (alternative to -sr)
-ts, --tests Comma-separated list of --tests (enables --test-level RunSpecifiedTests)
-hp, --help Show this help
EXAMPLES:
1) Real deploy with multiple flexipages (specific files):
sf-deploy -to DEMO-ORG \
-sr "force-app/main/default/flexipages/Sample_Page.flexipage-meta.xml,force-app/main/default/flexipages/Sample_Page_Backup_With_SalesNavigator.flexipage-meta.xml,force-app/main/default/flexipages/Sample_Role_Record_Page.flexipage-meta.xml"
2) Real deploy with entire directory:
sf-deploy -to DEMO-ORG -dr "force-app/main/default/classes"
3) Real deploy with specified tests:
sf-deploy -to DEMO-ORG \
-sr "force-app/main/default/flexipages/Demo_Page.flexipage-meta.xml,force-app/main/default/flexipages/Demo_Page_Backup_With_SalesNavigator.flexipage-meta.xml" \
-ts "SelectorOpportunity_Test,SelectorOpportunity2_Test"
Notes:
- Use -sr for specific files (comma-separated) OR -dr for entire directories (not both).
- Pass absolute or repo-relative paths.
- Multiple tests are comma-separated in -ts; they will be expanded to multiple --tests flags.
EOF
}
ORG=""
DIR_PATH=""
declare -a SOURCES_ARR=()
declare -a TESTS_ARR=()
if [[ $# -eq 0 ]]; then
show_help
exit 0
fi
# Parse command line arguments using manual parsing for two-character options
while [[ $# -gt 0 ]]; do
case $1 in
-to|--target-org)
ORG="$2"
shift 2
;;
-sr|--sources)
IFS=',' read -r -a SOURCES_ARR <<< "$2"
shift 2
;;
-dr|--directory)
DIR_PATH="$2"
shift 2
;;
-ts|--tests)
IFS=',' read -r -a TESTS_ARR <<< "$2"
shift 2
;;
-hp|--help)
show_help
exit 0
;;
*)
echo "Unknown option: $1" >&2
echo
show_help
exit 1
;;
esac
done
# Validate that either -sr or -dr is provided, but not both
if [[ -n "$DIR_PATH" && ${#SOURCES_ARR[@]} -gt 0 ]]; then
echo "Error: Cannot use both -sr and -dr options. Use -sr for specific files or -dr for directories." >&2
echo
show_help
exit 1
fi
# Validate that at least one source option is provided
if [[ -z "$DIR_PATH" && ${#SOURCES_ARR[@]} -eq 0 ]]; then
echo "Error: Must provide either -sr (specific files) or -dr (directory path)." >&2
echo
show_help
exit 1
fi
# Silent environment check - verify SF CLI is available
if ! command -v sf >/dev/null 2>&1; then
echo "❌ Salesforce CLI (sf) not found!"
echo
echo "Running environment check to help you get started..."
echo
# Try to find and run sf-check in the same directory as this script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [[ -x "$SCRIPT_DIR/sf-check" ]]; then
"$SCRIPT_DIR/sf-check"
elif command -v sf-check >/dev/null 2>&1; then
sf-check
else
echo "sf-check not found. Please install the Salesforce CLI from:"
echo "https://developer.salesforce.com/tools/sfdxcli"
fi
exit 1
fi
CMD=(sf project deploy start)
# sources (specific files)
for SRC in "${SOURCES_ARR[@]:-}"; do
[[ -n "$SRC" ]] && CMD+=(--source-dir "$SRC")
done
# directory path
[[ -n "$DIR_PATH" ]] && CMD+=(--source-dir "$DIR_PATH")
# org
[[ -n "$ORG" ]] && CMD+=(--target-org "$ORG")
# tests
if [[ ${#TESTS_ARR[@]:-0} -gt 0 ]]; then
CMD+=(--test-level RunSpecifiedTests)
for T in "${TESTS_ARR[@]}"; do
[[ -n "$T" ]] && CMD+=(--tests "$T")
done
fi
echo ">>> Running: ${CMD[*]}"
exec "${CMD[@]}"