Skip to content

Commit b3d385d

Browse files
committed
chore: Add fallback to run astyle via uvx or pipx if not found in PATH
This change improves the runastyle scripts to support multiple ways of invoking astyle.
1 parent 421b688 commit b3d385d

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

runastyle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ ASTYLE_VERSION="3.4.13"
1515
ASTYLE_VERSION_STR="Artistic Style Version ${ASTYLE_VERSION}"
1616
ASTYLE="astyle"
1717

18+
if command -v astyle &> /dev/null; then
19+
ASTYLE="astyle"
20+
elif command -v uvx &> /dev/null; then
21+
ASTYLE="uvx --quiet ${ASTYLE}==${ASTYLE_VERSION}"
22+
elif command -v pipx &> /dev/null; then
23+
ASTYLE="pipx run --quiet ${ASTYLE}==${ASTYLE_VERSION}"
24+
else
25+
echo "Neither astyle, uvx, nor pipx found in PATH"
26+
exit 1
27+
fi
28+
1829
DETECTED_VERSION_STR=`$ASTYLE --version 2>&1`
1930
if [[ "$DETECTED_VERSION_STR" != ${ASTYLE_VERSION_STR}* ]]; then
2031
echo "You should use: ${ASTYLE_VERSION_STR}";

runastyle.bat

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,24 @@ REM ASTYLE_VERSION_STR is then constructed to match the beginning of the
1616
REM version string reported by "astyle --version".
1717
SET ASTYLE_VERSION="3.4.13"
1818
SET ASTYLE_VERSION_STR="Artistic Style Version %ASTYLE_VERSION%"
19-
SET ASTYLE="astyle"
19+
20+
REM Prefer system astyle; else try uvx; else pipx
21+
SET "ASTYLE=astyle"
22+
where astyle >nul 2>nul
23+
IF %errorlevel% neq 0 (
24+
where uvx >nul 2>nul
25+
IF %errorlevel% eq 0 (
26+
SET "ASTYLE=uvx --quiet astyle==%ASTYLE_VERSION%"
27+
) ELSE (
28+
where pipx >nul 2>nul
29+
IF %errorlevel% eq 0 (
30+
SET "ASTYLE=pipx run --quiet astyle==%ASTYLE_VERSION%"
31+
) ELSE (
32+
ECHO ERROR: Neither astyle, uvx, nor pipx found in PATH.
33+
GOTO EXIT_ERROR
34+
)
35+
)
36+
)
2037

2138
SET DETECTED_VERSION_STR=""
2239
FOR /F "tokens=*" %%i IN ('%ASTYLE% --version') DO SET DETECTED_VERSION_STR=%%i

0 commit comments

Comments
 (0)