#!/usr/bin/env bash set -euo pipefail show_help() { cat <<'EOF' sf-open-web — wrapper for `sf org open` USAGE: sf-open-web [-o ] [-p ] [-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[@]}"