@echo off

REM variable
set CURRENT_WORKSPACE_PATH=%cd%
::set HOME_PATH=%~dp0..\
set LIB_PATH=%HOME_PATH%lib-ncli

pushd "%~dp0"

::set LIB_PATH=%HOME_PATH%lib-ncli
set LIB_PATH=..\lib-ncli

::set CONFIG_PATH=%HOME_PATH%conf-ncli
set CONFIG_PATH=..\conf-ncli
set LOG_CONF_FILE=log4j-progress.xml
set LOG_OPT=-Dlog4j.configuration=%LOG_CONF_FILE%

set HAVE_ARGS=false
set CLASSPATH=
set ARGS=

REM check args
call:ARGS_SHIFT %*

REM check args
call:ARGS_CHECK %*

REM running command
call:_run_command %*

REM method call end
:END_STEP
REM goto:eof
exit /b %ERRORLEVEL%

REM command line shift method
:ARGS_SHIFT
if [%1]==[] goto AFTER_LOOP
set ARGS=%ARGS% %1
set HAVE_ARGS=true
SHIFT
goto ARGS_SHIFT
:AFTER_LOOP
goto:END_STEP

REM arguements check method
:ARGS_CHECK
if %HAVE_ARGS% == true goto ADD_ARGS
goto REMOVE_ARGS
goto:END_STEP

REM add workspace
:ADD_ARGS
set ARGS=%ARGS% --current-workspace-path "%CURRENT_WORKSPACE_PATH%"
goto:END_STEP

REM arguements check method
:REMOVE_ARGS
set ARGS=
REM
goto:END_STEP

REM command excute method
:_run_command

    FOR /f "tokens=*" %%i IN ('dir %LIB_PATH% /B') DO ( call:CONCAT %LIB_PATH%\%%i )

    set CLASSPATH="%CONFIG_PATH%";%CLASSPATH%

    set MAIN=org.tizen.ncli.ide.shell.Main
    set EXEC=java %LOG_OPT% -Djava.library.path=%LIB_PATH%\spawner -cp %CONFIG_PATH%;%CLASSPATH% %MAIN% %ARGS%

    %EXEC%
    popd
goto:END_STEP

REM concatenation lib
:CONCAT
    set CLASSPATH=%CLASSPATH%%1;
goto:END_STEP
