Skip to content

Commit 030f1f6

Browse files
committed
[build] allow passing rake flags to go scripts with -- separator
1 parent 0c0d458 commit 030f1f6

File tree

2 files changed

+70
-22
lines changed

2 files changed

+70
-22
lines changed

go

+26-11
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,38 @@ unset GEM_PATH
66

77
JAVA_OPTS="-client -Xmx4096m -XX:ReservedCodeCacheSize=512m -XX:MetaspaceSize=1024m --add-modules java.se --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/javax.crypto=ALL-UNNAMED"
88

9+
# This code supports both:
10+
# ./go "namespace:task[--arg1,--arg2]" --rake-flag
11+
# ./go namespace:task --arg1 --arg2 -- --rake-flag
12+
913
# The first argument is always the Rake task name
1014
task="$1"
11-
12-
# Shift the task off and get the remaining arguments
1315
shift
1416

15-
# Leave task alone if already passing in arguments the normal way
16-
if [[ "$task" != *[*]* ]]; then
17-
# Combine remaining arguments into a single string, clean up spaces after commas, and replace spaces with commas
18-
args=$(IFS=' '; echo "$*" | sed -e 's/,[ ]*/,/g' -e 's/ /,/g')
17+
# Initialize arrays for rake flags and task arguments
18+
rake_flags=()
19+
task_args=()
1920

20-
# If there are any arguments, format them as task[arg1,arg2,...]
21-
if [ -n "$args" ]; then
22-
task="$task[$args]"
23-
echo "Executing rake task: $task"
21+
# Arguments before -- are task arguments
22+
while [ $# -gt 0 ]; do
23+
if [ "$1" = "--" ]; then
24+
shift
25+
break
2426
fi
27+
task_args+=("$1")
28+
shift
29+
done
30+
31+
# Remaining arguments are rake flags
32+
rake_flags=("$@")
33+
34+
# If we have task args, format them
35+
if [ ${#task_args[@]} -gt 0 ]; then
36+
# Convert task args array to comma-separated string
37+
args=$(IFS=','; echo "${task_args[*]}")
38+
task="$task[$args]"
39+
echo "Executing rake task: $task"
2540
fi
2641

27-
java $JAVA_OPTS -jar third_party/jruby/jruby-complete.jar -X-C -S rake $task
2842

43+
java $JAVA_OPTS -jar third_party/jruby/jruby-complete.jar -X-C -S rake $task "${rake_flags[@]}"

go.bat

+44-11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ REM we want jruby-complete to take care of all things ruby
55
SET GEM_HOME=
66
SET GEM_PATH=
77

8+
# This code supports both:
9+
# ./go "namespace:task[--arg1,--arg2]" --rake-flag
10+
# ./go namespace:task --arg1 --arg2 -- --rake-flag
11+
812
REM The first argument is always the Rake task name
913
SET task=%1
1014

@@ -14,33 +18,62 @@ IF "%task%"=="" (
1418
exit /b 1
1519
)
1620

17-
REM Shift the task off and get the remaining arguments
21+
REM Shift the task off
1822
SHIFT
1923

2024
REM Leave task alone if already passing in arguments the normal way
2125
ECHO %task% | FINDSTR /C:"[" >NUL
2226
IF %ERRORLEVEL% EQU 0 (
23-
GOTO execute
27+
GOTO execute_with_args
2428
)
2529

26-
REM Process remaining arguments
27-
SET args=
30+
REM Initialize variables for task arguments and rake flags
31+
SET task_args=
32+
SET rake_flags=
33+
SET separator_found=false
34+
35+
REM Process arguments until we find --
2836
:process_args
2937
IF "%1"=="" GOTO done_args
30-
IF "!args!"=="" (
31-
SET args=%1
38+
39+
IF "%1"=="--" (
40+
SET separator_found=true
41+
SHIFT
42+
GOTO collect_rake_flags
43+
)
44+
45+
REM Add to task arguments
46+
IF "!task_args!"=="" (
47+
SET task_args=%1
3248
) ELSE (
33-
SET args=!args!,%1
49+
SET task_args=!task_args!,%1
3450
)
3551
SHIFT
3652
GOTO process_args
3753

54+
REM Collect remaining arguments as rake flags
55+
:collect_rake_flags
56+
IF "%1"=="" GOTO done_args
57+
IF "!rake_flags!"=="" (
58+
SET rake_flags=%1
59+
) ELSE (
60+
SET rake_flags=!rake_flags! %1
61+
)
62+
SHIFT
63+
GOTO collect_rake_flags
64+
3865
:done_args
39-
REM If there are any arguments, format them as task[arg1,arg2,...]
40-
IF NOT "!args!"=="" (
41-
SET task=%task%[!args!]
66+
REM If we have task args, format them as task[arg1,arg2,...]
67+
IF NOT "!task_args!"=="" (
68+
SET task=%task%[!task_args!]
4269
ECHO Executing rake task: %task%
4370
)
4471

4572
:execute
46-
java %JAVA_OPTS% -jar third_party\jruby\jruby-complete.jar -X-C -S rake %task%
73+
REM Execute rake with the task and flags
74+
java %JAVA_OPTS% -jar third_party\jruby\jruby-complete.jar -X-C -S rake %task% %rake_flags%
75+
GOTO :EOF
76+
77+
:execute_with_args
78+
REM Task already has arguments in brackets, pass remaining args directly to rake
79+
java %JAVA_OPTS% -jar third_party\jruby\jruby-complete.jar -X-C -S rake %task% %*

0 commit comments

Comments
 (0)