Files
sf-cli-wrapper/sf-web-open
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

97 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
show_help() {
cat <<'EOF'
sf-web-open — wrapper for `sf org open`
USAGE:
sf-web-open [-to <ORG_ALIAS_OR_USERNAME>] [-pt <RELATIVE_PATH>] [-ur]
OPTIONS:
-to, --target-org Org alias or username to pass as --target-org
-pt, --path Relative path to open inside the org (e.g., "/lightning/setup/SetupOneHome/home")
-ur, --url-only URL-only: print the URL instead of opening a browser (passes --url-only)
-hp, --help Show this help
EXAMPLES:
1) Open a specific org (default home):
sf-web-open -to DEMO-ORG
2) Open Setup Home of a target org:
sf-web-open -to NUSHUB-DR2 -pt "/lightning/setup/SetupOneHome/home"
3) Get just the URL for scripting:
sf-web-open -to NUSHUB-DR2 -ur
4) Open the current default org (no -to provided):
sf-web-open
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
# 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
;;
-pt|--path)
PATH_ARG="$2"
shift 2
;;
-ur|--url-only)
URL_ONLY=1
shift
;;
-hp|--help)
show_help
exit 0
;;
*)
echo "Unknown option: $1" >&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[@]}"