Skip to content

Commit 0c9fe44

Browse files
authored
Create runsample.bat script for Windows (#275)
For those of us still using Windows without WSL, B4W... While I was at it, I've also fixed a few shellcheck warnings in the original runsample script and made it exit upon encountering an empty string.
1 parent 979fcdf commit 0c9fe44

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

runsample

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
task=$1
77
shift 1
88

9-
if [ ! -d "samples/${task}" ]; then
10-
echo "Unknown sample ${task}"
9+
if [ -z "${task}" ] || [ ! -d "samples/${task}" ]
10+
then
11+
echo "Unknown sample: '${task}'"
1112
exit 1
1213
fi
1314

14-
./gradlew --quiet :samples:${task}:installDist
15-
16-
./samples/${task}/build/install/${task}/bin/${task} "$@"
15+
./gradlew --quiet ":samples:${task}:installDist" && "./samples/${task}/build/install/${task}/bin/${task}" "$@"

runsample.bat

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@if "%DEBUG%"=="" @echo off
2+
:: Run one of the samples.
3+
:: The first argument must be the name of the sample task (e.g. echo).
4+
:: Any remaining arguments are forwarded to the sample's argv.
5+
6+
if "%OS%"=="Windows_NT" setlocal EnableDelayedExpansion
7+
8+
set TASK=%~1
9+
10+
set SAMPLE=false
11+
if defined TASK if not "!TASK: =!"=="" if exist "samples\%TASK%\*" set SAMPLE=true
12+
13+
if "%SAMPLE%"=="false" (
14+
echo Unknown sample: '%TASK%'
15+
exit /b 1
16+
)
17+
18+
set ARGS=%*
19+
set ARGS=!ARGS:*%1=!
20+
if "!ARGS:~0,1!"==" " set ARGS=!ARGS:~1!
21+
22+
call gradlew --quiet ":samples:%TASK%:installDist" && call "samples\%TASK%\build\install\%TASK%\bin\%TASK%" %ARGS%
23+
24+
if "%OS%"=="Windows_NT" endlocal

0 commit comments

Comments
 (0)