added sf cli wrappers

This commit is contained in:
reynold
2025-08-28 15:27:24 +08:00
parent 0b2e2f619f
commit b09cbed174
3 changed files with 204 additions and 0 deletions

72
sf-deploy Executable file
View File

@@ -0,0 +1,72 @@
#!/usr/bin/env bash
set -euo pipefail
show_help() {
cat <<'EOF'
sf-deploy — wrapper for `sf project deploy start`
USAGE:
sf-deploy -o <ORG_ALIAS_OR_USERNAME> -s "<src1>,<src2>[,...]" [-t "<Test1>,<Test2>[,...]"]
OPTIONS:
-o Org alias or username for --target-org
-s Comma-separated list of --source-dir paths
-t Comma-separated list of --tests (enables --test-level RunSpecifiedTests)
-h Show this help
EXAMPLES:
1) Real deploy with multiple flexipages:
sf-deploy -o DEMO-ORG \
-s "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 specified tests:
sf-deploy -o DEMO-ORG \
-s "force-app/main/default/flexipages/Demo_Page.flexipage-meta.xml,force-app/main/default/flexipages/Demo_Page_Backup_With_SalesNavigator.flexipage-meta.xml" \
-t "SelectorOpportunity_Test,SelectorOpportunity2_Test"
Notes:
- Pass absolute or repo-relative paths in -s, separated by commas.
- Multiple tests are comma-separated in -t; they will be expanded to multiple --tests flags.
EOF
}
ORG=""
declare -a SOURCES_ARR=()
declare -a TESTS_ARR=()
if [[ $# -eq 0 ]]; then
show_help
exit 0
fi
while getopts ":o:s:t:h" opt; do
case "$opt" in
o) ORG="$OPTARG" ;;
s) IFS=',' read -r -a SOURCES_ARR <<< "$OPTARG" ;;
t) IFS=',' read -r -a TESTS_ARR <<< "$OPTARG" ;;
h) show_help; exit 0 ;;
\?) echo "Unknown option: -$OPTARG" >&2; echo; show_help; exit 1 ;;
:) echo "Option -$OPTARG requires an argument." >&2; echo; show_help; exit 1 ;;
esac
done
CMD=(sf project deploy start)
# sources
for SRC in "${SOURCES_ARR[@]:-}"; do
[[ -n "$SRC" ]] && CMD+=(--source-dir "$SRC")
done
# 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[@]}"

72
sf-dry-run Executable file
View File

@@ -0,0 +1,72 @@
#!/usr/bin/env bash
set -euo pipefail
show_help() {
cat <<'EOF'
sf-dry-run — wrapper for `sf project deploy start --dry-run`
USAGE:
sf-dry-run -o <ORG_ALIAS_OR_USERNAME> -s "<src1>,<src2>[,...]" [-t "<Test1>,<Test2>[,...]"]
OPTIONS:
-o Org alias or username for --target-org
-s Comma-separated list of --source-dir paths
-t Comma-separated list of --tests (enables --test-level RunSpecifiedTests)
-h Show this help
EXAMPLES:
1) Basic dry-run with multiple flexipages:
sf-dry-run -o DEMO-ORG \
-s "force-app/main/default/flexipages/Sample_Page.flexipage-meta.xml,force-app/main/default/flexipages/Sample_SalesNavigator.flexipage-meta.xml,force-app/main/default/flexipages/Sample_Role_Record_Page.flexipage-meta.xml"
2) Dry-run with specified tests:
sf-dry-run -o DEMO-ORG \
-s "force-app/main/default/flexipages/Demo_Page.flexipage-meta.xml,force-app/main/default/flexipages/Demo_Page_Backup_With_SalesNavigator.flexipage-meta.xml" \
-t "SelectorOpportunity_Test,SelectorOpportunity2_Test"
Notes:
- Pass absolute or repo-relative paths in -s, separated by commas.
- Multiple tests are comma-separated in -t; they will be expanded to multiple --tests flags.
EOF
}
ORG=""
declare -a SOURCES_ARR=()
declare -a TESTS_ARR=()
if [[ $# -eq 0 ]]; then
show_help
exit 0
fi
while getopts ":o:s:t:h" opt; do
case "$opt" in
o) ORG="$OPTARG" ;;
s) IFS=',' read -r -a SOURCES_ARR <<< "$OPTARG" ;;
t) IFS=',' read -r -a TESTS_ARR <<< "$OPTARG" ;;
h) show_help; exit 0 ;;
\?) echo "Unknown option: -$OPTARG" >&2; echo; show_help; exit 1 ;;
:) echo "Option -$OPTARG requires an argument." >&2; echo; show_help; exit 1 ;;
esac
done
CMD=(sf project deploy start --dry-run)
# sources
for SRC in "${SOURCES_ARR[@]:-}"; do
[[ -n "$SRC" ]] && CMD+=(--source-dir "$SRC")
done
# 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[@]}"

60
sf-web-open Executable file
View File

@@ -0,0 +1,60 @@
#!/usr/bin/env bash
set -euo pipefail
show_help() {
cat <<'EOF'
sf-open-web — wrapper for `sf org open`
USAGE:
sf-open-web [-o <ORG_ALIAS_OR_USERNAME>] [-p <RELATIVE_PATH>] [-U]
OPTIONS:
-o Org alias or username to pass as --target-org
-p Relative path to open inside the org (e.g., "/lightning/setup/SetupOneHome/home")
-U URL-only: print the URL instead of opening a browser (passes --url-only)
-h Show this help
EXAMPLES:
1) Open a specific org (default home):
sf-open-web -o DEMO-ORG
2) Open Setup Home of a target org:
sf-open-web -o NUSHUB-DR2 -p "/lightning/setup/SetupOneHome/home"
3) Get just the URL for scripting:
sf-open-web -o NUSHUB-DR2 -U
4) Open the current default org (no -o provided):
sf-open-web
EOF
}
ORG=""
PATH_ARG=""
URL_ONLY=0
# If no args → show help + examples and exit without error
if [[ $# -eq 0 ]]; then
show_help
exit 0
fi
while getopts ":o:p:Uh" opt; do
case "$opt" in
o) ORG="$OPTARG" ;;
p) PATH_ARG="$OPTARG" ;;
U) URL_ONLY=1 ;;
h) show_help; exit 0 ;;
\?) echo "Unknown option: -$OPTARG" >&2; echo; show_help; exit 1 ;;
:) echo "Option -$OPTARG requires an argument." >&2; echo; show_help; exit 1 ;;
esac
done
CMD=(sf org open)
[[ -n "$ORG" ]] && CMD+=(--target-org "$ORG")
[[ -n "$PATH_ARG" ]] && CMD+=(--path "$PATH_ARG")
[[ $URL_ONLY -eq 1 ]] && CMD+=(--url-only)
echo ">>> Running: ${CMD[*]}"
exec "${CMD[@]}"