Created
November 8, 2016 20:12
-
-
Save mlocati/ec7de6c4fdd91c1af83c50a6c341457a to your computer and use it in GitHub Desktop.
Call php-cs-fixer by automatically locating the configuration file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal enabledelayedexpansion | |
if "%~1" equ "" ( | |
echo Missing file name>&2 | |
goto :eof | |
) | |
if "%~2" neq "" ( | |
echo Too many arguments>&2 | |
goto :eof | |
) | |
if not exist "%~1" ( | |
echo File not found: %~1>&2 | |
goto :eof | |
) | |
if exist "%~1\*.*" ( | |
echo File needed: %~1 is a directory>&2 | |
goto :eof | |
) | |
set FILENAME=%~dpnx1 | |
set DIRNAME=%~dp1 | |
set DIRNAME=%DIRNAME:~0,-1% | |
:checkParent | |
set CONFIG=%DIRNAME%\.php_cs | |
if exist "%CONFIG%" goto :found | |
call :getParent %DIRNAME% DIRNAME | |
if "%DIRNAME%" equ "." ( | |
echo Configuration file not found>&2 | |
goto :eof | |
) | |
goto checkParent | |
:found | |
C:\Dev\PHP7.0-64\php.exe "%~dp0php-cs-fixer.phar" fix --config-file="%CONFIG%" "%FILENAME%" | |
goto :eof | |
:getParent | |
set %2=. | |
if "%1" equ "." exit /b | |
if "%1" equ "" exit /b | |
set P1=%~dp1 | |
set P2=%P1:~0,-1% | |
if "%P2:~0,2%" equ "%P2:~0,3%" exit /b | |
set %2=%P2% | |
exit /b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
notepad
nppExec