@ECHO OFF

set argC=0
for %%x in (%*) do Set /A argC+=1
IF "%argC%" == "0" (
   echo Error: Argument missing. use '-h' for help.
   goto end
)

set sdk_path=%~dp0

setlocal enabledelayedexpansion
IF EXIST !sdk_path! (
	set em_path=!sdk_path!
) ELSE (
	set em_path=.
)

setlocal disabledelayedexpansion
set current_path=%CD%\em-cli.jar

for /F "usebackq tokens=1,2* delims=: " %%V in (`mode con`) do (
    if .%%V==.Columns (
        set COLUMNS=%%W
        goto done
    )
)

:done

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: (W/A) In java 9, JAXB module should be added in run time.
:: But this is a temporary workaround because eventually
:: modules that are not resolved by default such as a JAXB
:: could be removed from the JDK.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set jre_opt="--add-modules=java.xml.bind -XX:+IgnoreUnrecognizedVMOptions"

IF EXIST "%current_path%" (
	java "%jre_opt%" -jar "%current_path%" %*
) ELSE (
	java "%jre_opt%" -jar "%em_path%\em-cli.jar" %*
)

:end
