feat(clone-app): add extract-package.sh URL parser with tests
This commit is contained in:
parent
9550dc0182
commit
bc3066a890
|
|
@ -0,0 +1,23 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
input="${1:-}"
|
||||||
|
if [[ -z "$input" ]]; then
|
||||||
|
echo "ERROR: usage: extract-package.sh <play-url-or-package>" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Case 1: full URL containing id=<package>
|
||||||
|
if [[ "$input" =~ id=([a-zA-Z0-9._]+) ]]; then
|
||||||
|
echo "${BASH_REMATCH[1]}"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Case 2: already a bare package (must contain a dot, valid chars only)
|
||||||
|
if [[ "$input" =~ ^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$ ]]; then
|
||||||
|
echo "$input"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "ERROR: could not extract package from '$input'" >&2
|
||||||
|
exit 1
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -uo pipefail
|
||||||
|
SCRIPT="$(dirname "$0")/../skills/clone-app/scripts/extract-package.sh"
|
||||||
|
fail=0
|
||||||
|
check() {
|
||||||
|
local desc="$1" expected="$2" actual="$3"
|
||||||
|
if [[ "$expected" == "$actual" ]]; then
|
||||||
|
echo "PASS: $desc"
|
||||||
|
else
|
||||||
|
echo "FAIL: $desc — expected '$expected' got '$actual'"; fail=1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check "full url" "com.example.app" \
|
||||||
|
"$(bash "$SCRIPT" 'https://play.google.com/store/apps/details?id=com.example.app')"
|
||||||
|
check "url with extra params" "com.whatsapp" \
|
||||||
|
"$(bash "$SCRIPT" 'https://play.google.com/store/apps/details?id=com.whatsapp&hl=en&gl=US')"
|
||||||
|
check "bare package passthrough" "com.spotify.music" \
|
||||||
|
"$(bash "$SCRIPT" 'com.spotify.music')"
|
||||||
|
|
||||||
|
# invalid input → exit 1, empty stdout
|
||||||
|
out="$(bash "$SCRIPT" 'not a url' 2>/dev/null)"; rc=$?
|
||||||
|
check "invalid exit code" "1" "$rc"
|
||||||
|
check "invalid empty stdout" "" "$out"
|
||||||
|
|
||||||
|
exit $fail
|
||||||
Loading…
Reference in New Issue