@echo off
set SCRIPT=%0
set CLI_HOME=%~dp0\..

set MAIN=org.tizen.common.sign.signer.TizenSigner

set classpath=

FOR %%i IN ("%CLI_HOME%\lib\*.jar") DO ( call:CONCAT %%i )

set OPT_TRACE=
set OPT_LOGGING=-Dlog4j.configuration=log4j.xml
set OPT_PRG_NAME=-Dcli.name=%SCRIPT%

set READ_ARG=n

FOR %%W IN ( %* ) DO ( call:parseArg %%W )

set OPT=%OPT_TRACE% %OPT_LOGGING% %OPT_PRG_NAME%
set EXEC=java -cp %CLI_HOME%\conf;%classpath% %OPT% %MAIN% %*

IF NOT "" == "%OPT_TRACE%" ( echo Command :%EXEC% )

%EXEC%
IF %errorlevel% NEQ 0 (exit 1)
goto:eof

:parseArg
        IF y == %READ_ARG% goto SET_LOGGING

:SECOND_STEP
    IF %1 == --log goto SET_READY
    IF %1 == -l goto SET_READY
:END_STEP
goto:eof

:SET_LOGGING
    set OPT_LOGGING=-Dlog4j.configuration=log4j-%~1.xml
    IF %1 == trace set OPT_TRACE=-Dlog4j.debug=true
    set READ_ARG=n

    goto SECOND_STEP

:SET_READY
    set READ_ARG=y
    goto END_STEP

:CONCAT
    set classpath=%classpath%%1;

