110 lines
2.6 KiB
Bash
Executable File
110 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
show_help() {
|
|
cat <<'EOF'
|
|
sf-web-login — wrapper for `sf org login web`
|
|
|
|
USAGE:
|
|
sf-web-login [-al <ALIAS>] [-in <INSTANCE_URL>] [-ud] [-hp] [-ve]
|
|
|
|
OPTIONS:
|
|
-al Alias for the authenticated org (passes --alias)
|
|
-in Instance URL to authenticate against (passes --instance-url)
|
|
-ud Update default org after login (passes --set-default)
|
|
-ve Enable verbose output
|
|
-hp Show this help
|
|
|
|
EXAMPLES:
|
|
1) Login to production with alias:
|
|
sf-web-login -al NUSHUB-PROD
|
|
|
|
2) Login to specific instance with alias and set as default:
|
|
sf-web-login -al MySandbox -in https://test.my-domain.my.salesforce.com -ud
|
|
|
|
3) Simple login (will prompt for alias):
|
|
sf-web-login
|
|
EOF
|
|
}
|
|
|
|
ALIAS=""
|
|
INSTANCE_URL=""
|
|
SET_DEFAULT=0
|
|
VERBOSE=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
|
|
-al)
|
|
ALIAS="$2"
|
|
shift 2
|
|
;;
|
|
-in)
|
|
INSTANCE_URL="$2"
|
|
shift 2
|
|
;;
|
|
-ud)
|
|
SET_DEFAULT=1
|
|
shift
|
|
;;
|
|
-ve)
|
|
VERBOSE=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 login web)
|
|
|
|
[[ -n "$ALIAS" ]] && CMD+=(--alias "$ALIAS")
|
|
[[ -n "$INSTANCE_URL" ]] && CMD+=(--instance-url "$INSTANCE_URL")
|
|
[[ $SET_DEFAULT -eq 1 ]] && CMD+=(--set-default)
|
|
|
|
if [[ $VERBOSE -eq 1 ]]; then
|
|
echo "🔐 Starting Web Login"
|
|
echo "===================="
|
|
[[ -n "$ALIAS" ]] && echo "Alias: $ALIAS"
|
|
[[ -n "$INSTANCE_URL" ]] && echo "Instance URL: $INSTANCE_URL"
|
|
[[ $SET_DEFAULT -eq 1 ]] && echo "Will set as default org: Yes"
|
|
echo
|
|
fi
|
|
|
|
echo ">>> Running: ${CMD[*]}"
|
|
exec "${CMD[@]}"
|