Files
sf-cli-wrapper/sf-web-open
reynold 4fcff2014d docs: remove redundant sf-web-open example 4
- Removed duplicate 'custom path' example from both bash and PowerShell scripts
- Example 2 already demonstrates custom path usage with Setup Home
- Updated README.md to match the streamlined 3-example format
- All examples now provide distinct, non-overlapping use cases
2025-08-28 23:18:56 +08:00

94 lines
2.2 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 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
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[@]}"