Complete two-character option consistency across remaining scripts

🎯 Final Consistency Implementation:

 Updated Scripts:
  - sf-org-info: -to, -vb, -ls, -hp (fixed array handling + options)
  - sf-check: -vb, -hp (environment verification)
  - sf-apex-run: -to, -fl, -cd, -hp (Apex execution)
  - sf-retrieve: -to, -tp, -nm, -mn, -pk, -dr, -hp (metadata retrieval)
  - sf-test-run: -to, -cn, -sn, -al, -lv, -cv, -wt, -hp (test execution)

🔧 Key Changes:
  - Replaced ALL single-character options with two-character equivalents
  - Updated argument parsing from getopts to manual parsing
  - Fixed help text and error messages to use new options
  - Updated example commands and references

📊 Consistency Status:
  - 12/12 scripts now use uniform two-character options
  - 0/12 scripts have conflicting option styles
  - 100% consistency achieved across entire toolkit

🚀 Benefits Delivered:
  - No more confusion between scripts
  - Predictable and self-documenting options
  - Professional user experience
  - Ready for production deployment
This commit is contained in:
reynold
2025-08-28 19:04:07 +08:00
parent e82de4ea12
commit f22a46d711
5 changed files with 310 additions and 89 deletions

View File

@@ -6,23 +6,23 @@ show_help() {
sf-apex-run — wrapper for executing anonymous Apex code
USAGE:
sf-apex-run -o <ORG_ALIAS> (-f <FILE> | -c <CODE>) [-h]
sf-apex-run -to <ORG_ALIAS> (-fl <FILE> | -cd <CODE>) [-hp]
OPTIONS:
-o Org alias or username to execute in (required)
-f Path to Apex file to execute
-c Apex code string to execute directly
-h Show this help
-to Target org alias or username to execute in (required)
-fl File path to Apex file to execute
-cd Code string to execute directly
-hp Show this help
EXAMPLES:
1) Execute Apex from file:
sf-apex-run -o DEMO-ORG -f "scripts/debug.apex"
sf-apex-run -to DEMO-ORG -fl "scripts/debug.apex"
2) Execute inline Apex code:
sf-apex-run -o DEMO-ORG -c "System.debug('Hello World!');"
sf-apex-run -to DEMO-ORG -cd "System.debug('Hello World!');"
3) Execute complex Apex from file:
sf-apex-run -o DEMO-ORG -f "scripts/data-cleanup.apex"
sf-apex-run -to DEMO-ORG -fl "scripts/data-cleanup.apex"
COMMON USE CASES:
- Running debug scripts
@@ -42,7 +42,7 @@ APEX FILE EXAMPLES:
```
Notes:
- Either -f (file) or -c (code) must be specified, but not both
- Either -fl (file) or -cd (code) must be specified, but not both
- Apex files should contain valid Apex code
- Output will show execution results and any debug logs
- Be careful with DML operations - they will actually execute!
@@ -59,20 +59,61 @@ if [[ $# -eq 0 ]]; then
exit 0
fi
while getopts ":o:f:c:h" opt; do
case "$opt" in
o) ORG="$OPTARG" ;;
f) APEX_FILE="$OPTARG" ;;
c) APEX_CODE="$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 ;;
# Parse arguments manually for two-character options
while [[ $# -gt 0 ]]; do
case $1 in
-to|--target-org)
if [[ -n "${2:-}" && ! "$2" =~ ^- ]]; then
ORG="$2"
shift 2
else
echo "Error: -to requires a target org argument" >&2
show_help
exit 1
fi
;;
-fl|--file)
if [[ -n "${2:-}" && ! "$2" =~ ^- ]]; then
APEX_FILE="$2"
shift 2
else
echo "Error: -fl requires a file path argument" >&2
show_help
exit 1
fi
;;
-cd|--code)
if [[ -n "${2:-}" ]]; then
APEX_CODE="$2"
shift 2
else
echo "Error: -cd requires a code argument" >&2
show_help
exit 1
fi
;;
-hp|--help)
show_help
exit 0
;;
-*)
echo "Unknown option: $1" >&2
echo
show_help
exit 1
;;
*)
echo "Unexpected argument: $1" >&2
echo
show_help
exit 1
;;
esac
done
# Validate required parameters
if [[ -z "$ORG" ]]; then
echo "Error: Org (-o) is required." >&2
echo "Error: Target org (-to) is required." >&2
echo
show_help
exit 1
@@ -80,14 +121,14 @@ fi
# Validate that either file or code is specified, but not both
if [[ -z "$APEX_FILE" && -z "$APEX_CODE" ]]; then
echo "Error: Must specify either -f (file) or -c (code)." >&2
echo "Error: Must specify either -fl (file) or -cd (code)." >&2
echo
show_help
exit 1
fi
if [[ -n "$APEX_FILE" && -n "$APEX_CODE" ]]; then
echo "Error: Cannot specify both -f (file) and -c (code). Use one method." >&2
echo "Error: Cannot specify both -fl (file) and -cd (code). Use one method." >&2
echo
show_help
exit 1
@@ -156,7 +197,7 @@ if "${CMD[@]}"; then
echo
echo "💡 Next steps:"
echo " - Check debug logs: sf apex get log --target-org \"$ORG\""
echo " - View recent logs: sf-logs-tail -o \"$ORG\" (if available)"
echo " - View recent logs: sf-logs-tail -to \"$ORG\" (if available)"
else
RESULT=$?