Levels of color used in a Windows bat script
Add log-level-like colored headers to your script output:
Clone batcolors into your bat script project and:
@echo off
setlocal enabledelayedexpansion
rem https://stackoverflow.com/questions/112055/what-does-d0-mean-in-a-windows-batch-file
for %%i in ("%~dp0.") do SET "script_dir=%%~fi"
set script_dir=%script_dir%\..
@echo %script_dir%
call %script_dir%\batcolors\echos_macros.bat
%_ok% "Result matches what was expected"
%_info% "Describe what is about to be done"
%_warning% "Result was not expected, but non-blocking"
%_error% "Result is wrong"
%_fatal% "Program must stop and exit" 1
REM final echo should not be displayed:
echo done%_error% will not exit your script, while %_fatal% will.
Any line after %_fatal% will not be executed (unless FATALNOEXIT is set. See below)
If you do not want ANSI escape code, simply set NOCOLORS=1.
Then unset it (set NOCOLORS=), and the next %_ok/info/...% call will display colors again.
If you don't want to exit on a %_fatal% call, set FATALNOEXIT=1 first.
Then, unset it (set FATALNOEXIT=), and the next %_fatal% call will exit the script.
