#!/usr/bin/env bash set -euo pipefail show_help() { cat <<'EOF' sf-web-open — wrapper for `sf org open` USAGE: sf-web-open [-to ] [-pt ] [-ur] OPTIONS: -to Org alias or username to pass as --target-org (recommended) -pt Relative path to open inside the org (e.g., "/lightning/setup/SetupOneHome/home") -ur URL-only: print the URL instead of opening a browser (passes --url-only) -hp 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 org with custom path: sf-web-open -to MYORG -pt "/lightning/setup/ObjectManager/home" 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) ORG="$2" shift 2 ;; -pt) PATH_ARG="$2" shift 2 ;; -ur) URL_ONLY=1 shift ;; -hp) 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[@]}"