Skip to content

Commit f02d746

Browse files
abueideclaude
andcommitted
refactor: use explicit flags for app run argument parsing
Replace heuristic positional parsing (sniffing for '/' or '.apk'/'.app' in args) with explicit --apk/--app and --device flags. Bare positional args are still accepted as device names for convenience and backward compatibility. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1f0ade9 commit f02d746

4 files changed

Lines changed: 113 additions & 49 deletions

File tree

plugins/android/virtenv/scripts/domain/deploy.sh

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -303,24 +303,33 @@ android_launch_app() {
303303
}
304304

305305
# Run Android app (build, install, launch)
306-
# Usage: android_run_app [apk_path] [device]
307-
# apk_path - Optional path to APK file. If provided, skips build step.
308-
# device - Optional device name. If omitted, uses ANDROID_DEFAULT_DEVICE.
306+
# Usage: android_run_app [--apk <path>] [--device <name>] [<device>]
307+
# --apk <path> - Path to APK file. If provided, skips build step.
308+
# --device <name> - Device name. If omitted, uses ANDROID_DEFAULT_DEVICE.
309+
# Bare positional arg is treated as device name for convenience.
309310
android_run_app() {
310-
# Parse arguments - first arg could be APK path or device name
311311
apk_arg=""
312312
device_choice=""
313313

314-
if [ $# -gt 0 ]; then
315-
# If first arg looks like a file path (contains / or ends with .apk), treat as APK
316-
if printf '%s' "$1" | grep -q -e '/' -e '\.apk$'; then
317-
apk_arg="$1"
318-
shift
319-
fi
320-
fi
321-
322-
# Remaining arg is device choice
323-
device_choice="${1:-}"
314+
while [ $# -gt 0 ]; do
315+
case "$1" in
316+
--apk)
317+
apk_arg="${2:-}"
318+
shift 2
319+
;;
320+
--device)
321+
device_choice="${2:-}"
322+
shift 2
323+
;;
324+
*)
325+
# Bare positional arg: treat as device name for convenience
326+
if [ -z "$device_choice" ]; then
327+
device_choice="$1"
328+
fi
329+
shift
330+
;;
331+
esac
332+
done
324333

325334
# ---- Resolve Device Selection ----
326335

plugins/android/virtenv/scripts/user/android.sh

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Commands:
3939
emulator reset Reset all emulator AVDs
4040
app status Check if deployed app is running
4141
app stop Stop the deployed app
42-
run [apk_path] [device] Start emulator, install, and launch app
42+
run [--apk path] [--device name] Start emulator, install, and launch app
4343
4444
Examples:
4545
android.sh deploy
@@ -55,8 +55,8 @@ Examples:
5555
android.sh app stop
5656
android.sh run # Start emulator, install, launch
5757
android.sh run max # Same, but on 'max' device
58-
android.sh run path/to/app.apk # Install provided APK
59-
android.sh run path/to/app.apk max # Install APK on 'max' device
58+
android.sh run --apk path/to/app.apk # Install provided APK
59+
android.sh run --apk app.apk --device max # Install APK on 'max' device
6060
6161
Note: Configuration is managed via environment variables in devbox.json.
6262
Note: Build your app with gradle directly (e.g., cd android && ./gradlew assembleDebug)
@@ -536,23 +536,32 @@ case "$command_name" in
536536

537537
# --------------------------------------------------------------------------
538538
# run - Build, install, and launch app on emulator
539-
# Usage: android.sh run [apk_path] [device]
539+
# Usage: android.sh run [--apk <path>] [--device <name>] [device]
540540
# --------------------------------------------------------------------------
541541
run)
542-
# Parse arguments - first arg could be APK path or device name
542+
# Parse arguments
543543
apk_arg=""
544544
device_name=""
545545

546-
if [ $# -gt 0 ]; then
547-
# If first arg looks like a file path (contains / or ends with .apk), treat as APK
548-
if printf '%s' "$1" | grep -q -e '/' -e '\.apk$'; then
549-
apk_arg="$1"
550-
shift
551-
fi
552-
fi
553-
554-
# Remaining arg is device name
555-
device_name="${1:-}"
546+
while [ $# -gt 0 ]; do
547+
case "$1" in
548+
--apk)
549+
apk_arg="${2:-}"
550+
shift 2
551+
;;
552+
--device)
553+
device_name="${2:-}"
554+
shift 2
555+
;;
556+
*)
557+
# Bare positional arg: treat as device name for convenience
558+
if [ -z "$device_name" ]; then
559+
device_name="$1"
560+
fi
561+
shift
562+
;;
563+
esac
564+
done
556565

557566
# Source layer 3 dependencies
558567
avd_script="${scripts_dir%/}/domain/avd.sh"
@@ -591,12 +600,16 @@ case "$command_name" in
591600
android_start_emulator "$device_name"
592601

593602
echo ""
594-
# Pass both APK (if provided) and device name to run
603+
# Pass both APK (if provided) and device name to run with explicit flags
604+
run_args=""
595605
if [ -n "$apk_arg" ]; then
596-
android_run_app "$apk_arg" "$device_name"
597-
else
598-
android_run_app "$device_name"
606+
run_args="--apk $apk_arg"
607+
fi
608+
if [ -n "$device_name" ]; then
609+
run_args="$run_args --device $device_name"
599610
fi
611+
# shellcheck disable=SC2086
612+
android_run_app $run_args
600613
;;
601614

602615
# --------------------------------------------------------------------------

plugins/ios/virtenv/scripts/domain/deploy.sh

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -327,24 +327,33 @@ ios_run_build() {
327327
# ============================================================================
328328

329329
# Build, install, and launch app on simulator
330-
# Usage: ios_run_app [app_path] [device]
331-
# app_path - Optional path to .app bundle. If provided, skips build step.
332-
# device - Optional device name. If omitted, uses IOS_DEFAULT_DEVICE.
330+
# Usage: ios_run_app [--app <path>] [--device <name>] [<device>]
331+
# --app <path> - Path to .app bundle. If provided, skips build step.
332+
# --device <name> - Device name. If omitted, uses IOS_DEFAULT_DEVICE.
333+
# Bare positional arg is treated as device name for convenience.
333334
ios_run_app() {
334-
# Parse arguments - first arg could be .app path or device name
335335
app_arg=""
336336
device_choice=""
337337

338-
if [ $# -gt 0 ]; then
339-
# If first arg looks like a path (contains / or ends with .app), treat as app path
340-
if printf '%s' "$1" | grep -q -e '/' -e '\.app$'; then
341-
app_arg="$1"
342-
shift
343-
fi
344-
fi
345-
346-
# Remaining arg is device choice
347-
device_choice="${1:-}"
338+
while [ $# -gt 0 ]; do
339+
case "$1" in
340+
--app)
341+
app_arg="${2:-}"
342+
shift 2
343+
;;
344+
--device)
345+
device_choice="${2:-}"
346+
shift 2
347+
;;
348+
*)
349+
# Bare positional arg: treat as device name for convenience
350+
if [ -z "$device_choice" ]; then
351+
device_choice="$1"
352+
fi
353+
shift
354+
;;
355+
esac
356+
done
348357

349358
# ---- Start Deployment ----
350359

plugins/ios/virtenv/scripts/user/ios.sh

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Commands:
1414
simulator reset
1515
app status Check if deployed app is running
1616
app stop Stop the deployed app
17-
run [app_path] [device] Start simulator, install, and launch app
17+
run [--app path] [--device name] Start simulator, install, and launch app
1818
xcodebuild [args...]
1919
config show
2020
info
@@ -486,7 +486,40 @@ case "$command_name" in
486486
run)
487487
# shellcheck disable=SC1090
488488
. "${script_dir}/domain/deploy.sh"
489-
ios_run_app "$@"
489+
490+
# Parse arguments
491+
_run_app_arg=""
492+
_run_device=""
493+
while [ $# -gt 0 ]; do
494+
case "$1" in
495+
--app)
496+
_run_app_arg="${2:-}"
497+
shift 2
498+
;;
499+
--device)
500+
_run_device="${2:-}"
501+
shift 2
502+
;;
503+
*)
504+
# Bare positional arg: treat as device name for convenience
505+
if [ -z "$_run_device" ]; then
506+
_run_device="$1"
507+
fi
508+
shift
509+
;;
510+
esac
511+
done
512+
513+
# Forward with explicit flags
514+
_run_args=""
515+
if [ -n "$_run_app_arg" ]; then
516+
_run_args="--app $_run_app_arg"
517+
fi
518+
if [ -n "$_run_device" ]; then
519+
_run_args="$_run_args --device $_run_device"
520+
fi
521+
# shellcheck disable=SC2086
522+
ios_run_app $_run_args
490523
;;
491524
config)
492525
sub="${1-}"

0 commit comments

Comments
 (0)