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
This commit is contained in:
reynold
2025-08-28 18:28:23 +08:00
parent 4bae7d48fa
commit 39b7f11646
4 changed files with 177 additions and 97 deletions

View File

@@ -6,32 +6,32 @@ show_help() {
sf-deploy — wrapper for `sf project deploy start`
USAGE:
sf-deploy -o <ORG_ALIAS_OR_USERNAME> (-s "<src1>,<src2>[,...]" | -d <DIRECTORY>) [-t "<Test1>,<Test2>[,...]"]
sf-deploy -to <ORG_ALIAS_OR_USERNAME> (-sr "<src1>,<src2>[,...]" | -dr <DIRECTORY>) [-ts "<Test1>,<Test2>[,...]"]
OPTIONS:
-o Org alias or username for --target-org
-s Comma-separated list of --source-dir paths
-d Single directory path to deploy (alternative to -s)
-t Comma-separated list of --tests (enables --test-level RunSpecifiedTests)
-h Show this help
-to, --target-org Org alias or username for --target-org
-sr, --sources Comma-separated list of --source-dir paths
-dr, --directory Single directory path to deploy (alternative to -sr)
-ts, --tests Comma-separated list of --tests (enables --test-level RunSpecifiedTests)
-hp, --help Show this help
EXAMPLES:
1) Real deploy with multiple flexipages (specific files):
sf-deploy -o DEMO-ORG \
-s "force-app/main/default/flexipages/Sample_Page.flexipage-meta.xml,force-app/main/default/flexipages/Sample_Page_Backup_With_SalesNavigator.flexipage-meta.xml,force-app/main/default/flexipages/Sample_Role_Record_Page.flexipage-meta.xml"
sf-deploy -to DEMO-ORG \
-sr "force-app/main/default/flexipages/Sample_Page.flexipage-meta.xml,force-app/main/default/flexipages/Sample_Page_Backup_With_SalesNavigator.flexipage-meta.xml,force-app/main/default/flexipages/Sample_Role_Record_Page.flexipage-meta.xml"
2) Real deploy with entire directory:
sf-deploy -o DEMO-ORG -d "force-app/main/default/classes"
sf-deploy -to DEMO-ORG -dr "force-app/main/default/classes"
3) Real deploy with specified tests:
sf-deploy -o DEMO-ORG \
-s "force-app/main/default/flexipages/Demo_Page.flexipage-meta.xml,force-app/main/default/flexipages/Demo_Page_Backup_With_SalesNavigator.flexipage-meta.xml" \
-t "SelectorOpportunity_Test,SelectorOpportunity2_Test"
sf-deploy -to DEMO-ORG \
-sr "force-app/main/default/flexipages/Demo_Page.flexipage-meta.xml,force-app/main/default/flexipages/Demo_Page_Backup_With_SalesNavigator.flexipage-meta.xml" \
-ts "SelectorOpportunity_Test,SelectorOpportunity2_Test"
Notes:
- Use -s for specific files (comma-separated) OR -d for entire directories (not both).
- Use -sr for specific files (comma-separated) OR -dr for entire directories (not both).
- Pass absolute or repo-relative paths.
- Multiple tests are comma-separated in -t; they will be expanded to multiple --tests flags.
- Multiple tests are comma-separated in -ts; they will be expanded to multiple --tests flags.
EOF
}
@@ -45,21 +45,41 @@ if [[ $# -eq 0 ]]; then
exit 0
fi
while getopts ":o:s:d:t:h" opt; do
case "$opt" in
o) ORG="$OPTARG" ;;
s) IFS=',' read -r -a SOURCES_ARR <<< "$OPTARG" ;;
d) DIR_PATH="$OPTARG" ;;
t) IFS=',' read -r -a TESTS_ARR <<< "$OPTARG" ;;
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
# 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
;;
-sr|--sources)
IFS=',' read -r -a SOURCES_ARR <<< "$2"
shift 2
;;
-dr|--directory)
DIR_PATH="$2"
shift 2
;;
-ts|--tests)
IFS=',' read -r -a TESTS_ARR <<< "$2"
shift 2
;;
-hp|--help)
show_help
exit 0
;;
*)
echo "Unknown option: $1" >&2
echo
show_help
exit 1
;;
esac
done
# Validate that either -s or -d is provided, but not both
# Validate that either -sr or -dr is provided, but not both
if [[ -n "$DIR_PATH" && ${#SOURCES_ARR[@]} -gt 0 ]]; then
echo "Error: Cannot use both -s and -d options. Use -s for specific files or -d for directories." >&2
echo "Error: Cannot use both -sr and -dr options. Use -sr for specific files or -dr for directories." >&2
echo
show_help
exit 1
@@ -67,7 +87,7 @@ fi
# Validate that at least one source option is provided
if [[ -z "$DIR_PATH" && ${#SOURCES_ARR[@]} -eq 0 ]]; then
echo "Error: Must provide either -s (specific files) or -d (directory path)." >&2
echo "Error: Must provide either -sr (specific files) or -dr (directory path)." >&2
echo
show_help
exit 1

View File

@@ -6,32 +6,32 @@ show_help() {
sf-dry-run — wrapper for `sf project deploy start --dry-run`
USAGE:
sf-dry-run -o <ORG_ALIAS_OR_USERNAME> (-s "<src1>,<src2>[,...]" | -d <DIRECTORY>) [-t "<Test1>,<Test2>[,...]"]
sf-dry-run -to <ORG_ALIAS_OR_USERNAME> (-sr "<src1>,<src2>[,...]" | -dr <DIRECTORY>) [-ts "<Test1>,<Test2>[,...]"]
OPTIONS:
-o Org alias or username for --target-org
-s Comma-separated list of --source-dir paths
-d Single directory path to validate (alternative to -s)
-t Comma-separated list of --tests (enables --test-level RunSpecifiedTests)
-h Show this help
-to, --target-org Org alias or username for --target-org
-sr, --sources Comma-separated list of --source-dir paths
-dr, --directory Single directory path to validate (alternative to -sr)
-ts, --tests Comma-separated list of --tests (enables --test-level RunSpecifiedTests)
-hp, --help Show this help
EXAMPLES:
1) Basic dry-run with multiple flexipages (specific files):
sf-dry-run -o DEMO-ORG \
-s "force-app/main/default/flexipages/Sample_Page.flexipage-meta.xml,force-app/main/default/flexipages/Sample_SalesNavigator.flexipage-meta.xml,force-app/main/default/flexipages/Sample_Role_Record_Page.flexipage-meta.xml"
sf-dry-run -to DEMO-ORG \
-sr "force-app/main/default/flexipages/Sample_Page.flexipage-meta.xml,force-app/main/default/flexipages/Sample_SalesNavigator.flexipage-meta.xml,force-app/main/default/flexipages/Sample_Role_Record_Page.flexipage-meta.xml"
2) Dry-run validation for entire directory:
sf-dry-run -o DEMO-ORG -d "force-app/main/default/classes"
sf-dry-run -to DEMO-ORG -dr "force-app/main/default/classes"
3) Dry-run with specified tests:
sf-dry-run -o DEMO-ORG \
-s "force-app/main/default/flexipages/Demo_Page.flexipage-meta.xml,force-app/main/default/flexipages/Demo_Page_Backup_With_SalesNavigator.flexipage-meta.xml" \
-t "SelectorOpportunity_Test,SelectorOpportunity2_Test"
sf-dry-run -to DEMO-ORG \
-sr "force-app/main/default/flexipages/Demo_Page.flexipage-meta.xml,force-app/main/default/flexipages/Demo_Page_Backup_With_SalesNavigator.flexipage-meta.xml" \
-ts "SelectorOpportunity_Test,SelectorOpportunity2_Test"
Notes:
- Use -s for specific files (comma-separated) OR -d for entire directories (not both).
- Use -sr for specific files (comma-separated) OR -dr for entire directories (not both).
- Pass absolute or repo-relative paths.
- Multiple tests are comma-separated in -t; they will be expanded to multiple --tests flags.
- Multiple tests are comma-separated in -ts; they will be expanded to multiple --tests flags.
EOF
}
@@ -45,21 +45,41 @@ if [[ $# -eq 0 ]]; then
exit 0
fi
while getopts ":o:s:d:t:h" opt; do
case "$opt" in
o) ORG="$OPTARG" ;;
s) IFS=',' read -r -a SOURCES_ARR <<< "$OPTARG" ;;
d) DIR_PATH="$OPTARG" ;;
t) IFS=',' read -r -a TESTS_ARR <<< "$OPTARG" ;;
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
# 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
;;
-sr|--sources)
IFS=',' read -r -a SOURCES_ARR <<< "$2"
shift 2
;;
-dr|--directory)
DIR_PATH="$2"
shift 2
;;
-ts|--tests)
IFS=',' read -r -a TESTS_ARR <<< "$2"
shift 2
;;
-hp|--help)
show_help
exit 0
;;
*)
echo "Unknown option: $1" >&2
echo
show_help
exit 1
;;
esac
done
# Validate that either -s or -d is provided, but not both
# Validate that either -sr or -dr is provided, but not both
if [[ -n "$DIR_PATH" && ${#SOURCES_ARR[@]} -gt 0 ]]; then
echo "Error: Cannot use both -s and -d options. Use -s for specific files or -d for directories." >&2
echo "Error: Cannot use both -sr and -dr options. Use -sr for specific files or -dr for directories." >&2
echo
show_help
exit 1
@@ -67,7 +87,7 @@ fi
# Validate that at least one source option is provided
if [[ -z "$DIR_PATH" && ${#SOURCES_ARR[@]} -eq 0 ]]; then
echo "Error: Must provide either -s (specific files) or -d (directory path)." >&2
echo "Error: Must provide either -sr (specific files) or -dr (directory path)." >&2
echo
show_help
exit 1

View File

@@ -6,28 +6,28 @@ show_help() {
sf-org-create — wrapper for smart scratch org creation
USAGE:
sf-org-create -n <ORG_NAME> [-d <DAYS>] [-f <CONFIG_FILE>] [-a <ALIAS>] [-t <TEMPLATE>] [-h]
sf-org-create -al <ORG_NAME> [-dd <DAYS>] [-df <CONFIG_FILE>] [-st] [-tp <TEMPLATE>] [-hp]
OPTIONS:
-n Name/alias for the new scratch org (required)
-d Duration in days (default: 7, max: 30)
-f Path to scratch org definition file (default: config/project-scratch-def.json)
-a Set as default org alias after creation
-t Use predefined template (standard, testing, minimal, full)
-h Show this help
-al, --alias Name/alias for the new scratch org (required)
-dd, --duration-days Duration in days (default: 7, max: 30)
-df, --def-file Path to scratch org definition file (default: config/project-scratch-def.json)
-st, --set-default Set as default org alias after creation
-tp, --template Use predefined template (standard, testing, minimal, full)
-hp, --help Show this help
EXAMPLES:
1) Create basic scratch org:
sf-org-create -n "MyDevOrg"
sf-org-create -al "MyDevOrg"
2) Create testing org for 1 day:
sf-org-create -n "QuickTest" -d 1 -t testing
sf-org-create -al "QuickTest" -dd 1 -tp testing
3) Create with custom config and set as default:
sf-org-create -n "MainDev" -d 14 -f "config/custom-scratch-def.json" -a
sf-org-create -al "MainDev" -dd 14 -df "config/custom-scratch-def.json" -st
4) Create full-featured org:
sf-org-create -n "FullEnv" -t full -d 30
sf-org-create -al "FullEnv" -tp full -dd 30
TEMPLATES:
- standard: Basic scratch org with common features
@@ -54,22 +54,45 @@ if [[ $# -eq 0 ]]; then
exit 0
fi
while getopts ":n:d:f:at:h" opt; do
case "$opt" in
n) ORG_NAME="$OPTARG" ;;
d) DURATION="$OPTARG" ;;
f) CONFIG_FILE="$OPTARG" ;;
a) SET_DEFAULT=true ;;
t) TEMPLATE="$OPTARG" ;;
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
# Parse command line arguments using manual parsing for two-character options
while [[ $# -gt 0 ]]; do
case $1 in
-al|--alias)
ORG_NAME="$2"
shift 2
;;
-dd|--duration-days)
DURATION="$2"
shift 2
;;
-df|--def-file)
CONFIG_FILE="$2"
shift 2
;;
-st|--set-default)
SET_DEFAULT=true
shift
;;
-tp|--template)
TEMPLATE="$2"
shift 2
;;
-hp|--help)
show_help
exit 0
;;
*)
echo "Unknown option: $1" >&2
echo
show_help
exit 1
;;
esac
done
# Validate required parameters
if [[ -z "$ORG_NAME" ]]; then
echo "Error: Org name (-n) is required." >&2
echo "Error: Org alias (-al) is required." >&2
echo
show_help
exit 1

View File

@@ -3,29 +3,29 @@ set -euo pipefail
show_help() {
cat <<'EOF'
sf-open-web — wrapper for `sf org open`
sf-web-open — wrapper for `sf org open`
USAGE:
sf-open-web [-o <ORG_ALIAS_OR_USERNAME>] [-p <RELATIVE_PATH>] [-U]
sf-web-open [-to <ORG_ALIAS_OR_USERNAME>] [-pt <RELATIVE_PATH>] [-ur]
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
-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-open-web -o DEMO-ORG
sf-web-open -to DEMO-ORG
2) Open Setup Home of a target org:
sf-open-web -o NUSHUB-DR2 -p "/lightning/setup/SetupOneHome/home"
sf-web-open -to NUSHUB-DR2 -pt "/lightning/setup/SetupOneHome/home"
3) Get just the URL for scripting:
sf-open-web -o NUSHUB-DR2 -U
sf-web-open -to NUSHUB-DR2 -ur
4) Open the current default org (no -o provided):
sf-open-web
4) Open the current default org (no -to provided):
sf-web-open
EOF
}
@@ -39,15 +39,32 @@ if [[ $# -eq 0 ]]; then
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
# 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