Files
sf-cli-wrapper/sf-web-open
2025-08-28 15:51:17 +08:00

80 lines
2.0 KiB
Bash
Executable File

#!/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
# 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 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[@]}"