Skip to content

Commit e8ea84b

Browse files
committed
compute correctly multiple & negated starters
1 parent 5e8236e commit e8ea84b

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

scripts/pit/lib/lib-args.sh

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,30 @@ EOF
5252
exit 1
5353
}
5454

55+
processStarters() {
56+
local arg="$1"
57+
# Check if we have ONLY exclusions (all items start with !)
58+
echo "$arg" | tr ',' '\n' | grep -v '^!' >/dev/null && {
59+
# Has positive starters - only use those (ignore exclusions)
60+
local S=""
61+
for i in `echo "$arg" | tr ',' ' '`; do
62+
[ "${i#\!}" = "$i" ] && { # This is NOT an exclusion
63+
local b=${i%%:*}
64+
local H=`printf "$PRESETS\n$DEMOS" | egrep "^$b$|/$b$|/$b[/:]|^$b[/:]" | head -1`
65+
[ -z "$H" ] && err "Unknown starter: $b" && exit 1
66+
S="${S:+$S,}$H"
67+
}
68+
done
69+
STARTERS="$S"
70+
} || {
71+
# Only exclusions - filter DEFAULT_STARTERS
72+
STARTERS="$DEFAULT_STARTERS"
73+
for i in `echo "$arg" | tr ',' ' '`; do
74+
STARTERS=`echo "$STARTERS" | tr ',' '\n' | egrep -v "^${i#\!}$" | tr '\n' ',' | sed 's/,$//'`
75+
done
76+
}
77+
}
78+
5579
## check arguments passed to `run.sh` script and set global variables
5680
checkArgs() {
5781
VERSION=current; export PORT=$DEFAULT_PORT; TIMEOUT=$DEFAULT_TIMEOUT; CLUSTER=pit; VENDOR=kind; CCVERSION=current
@@ -62,18 +86,7 @@ checkArgs() {
6286
--port=*) export PORT="$arg";;
6387
--generated) STARTERS=`echo "$PRESETS" | tr "\n" "," | sed -e 's/^,//' | sed -e 's/,$//'`;;
6488
--demos) STARTERS=`echo "$DEMOS" | tr "\n" "," | sed -e 's/^,//' | sed -e 's/,$//'`;;
65-
--start*=*)
66-
## discover valid starters, when only providing the project name without repo, folder, or branch parts
67-
S=""
68-
for i in `echo "$arg" | tr ',' ' '`
69-
do
70-
b=${i%%:*}
71-
n=${b#\!}
72-
H=`printf "$PRESETS\n$DEMOS" | egrep "^$n$|/$n$|/$n[/:]|^$n[/:]" | head -1`
73-
[ -z "$H" ] && err "Unknown starter: $n" && exit 1
74-
[ "$n" = "$i" ] && S="$S,$H" || S="$i"
75-
done
76-
STARTERS="$S";;
89+
--start*=*) processStarters "$arg" ;;
7790
--version=*) VERSION="$arg";;
7891
--timeout=*) TIMEOUT="$arg";;
7992
--jdk=*) JDK="$arg";;
@@ -99,12 +112,12 @@ checkArgs() {
99112
--pnpm) PNPM="-Dpnpm.enable=true";;
100113
--vite) VITE=true;;
101114
--list*)
102-
for i in `echo "${STARTERS#,}" | tr "," " "`; do
103-
[ "${i#\!}" != "$i" ] && STARTERS="" && DEFAULT_STARTERS=`echo "$DEFAULT_STARTERS" | grep -v "${i#\!}"`
104-
done
105-
[ -z "$STARTERS" ] && STARTERS="${DEFAULT_STARTERS}" || STARTERS=`echo "$STARTERS" | tr "," "\n" | grep ...`
115+
# If STARTERS is already set (from --starters), use it; otherwise use DEFAULT_STARTERS
116+
if [ -z "$STARTERS" ]; then
117+
STARTERS="$DEFAULT_STARTERS"
118+
fi
106119
[ -z "$arg" ] && arg=1
107-
echo "$STARTERS" | xargs -n $arg | tr ' ' ,
120+
echo "$STARTERS" | tr ',' '\n' | xargs -n $arg | tr ' ' ,
108121
exit 0
109122
;;
110123
--help) usage && exit 0;;

0 commit comments

Comments
 (0)