Permalink
Browse files

Improved argument parsing for node.cmd

  • Loading branch information...
1 parent de92b10 commit c70efc15e703e3b7f2db151e99dc78864f8439c7 @piscisaureus committed Aug 4, 2010
Showing with 38 additions and 10 deletions.
  1. +38 −10 resource/node.cmd
View
@@ -1,21 +1,49 @@
@echo off
+
+rem Keep changes to the environment within this script
setlocal
-set p=%~dp0
-set s=%~f1
-set path=%p%bin\;%path%
+rem Path to this script
+set cmd_path=%~dp0
+
+rem Set path to cygwin binutils
+set path=%cmd_path%bin\;%cmd_path%node\bin;%path%
+
+rem Start building the node command
+set run="%cmd_path%node\bin\node.exe"
+
+rem For each command line argument, try to convert to a cygwin path
+rem If cygpath can't convert it we assume that it is not meant to be a file/folder name and pass it as-is
+:loop
+
+rem Test if there are more arguments to convert
+if %1.==. goto :done
-if not "%s%"=="" goto :script
-"%p%node\bin\node.exe"
-goto :end
+rem Fetch the next argument
+set next_arg=%1
-:script
-for /f "delims=:" %%i in ('cygpath "%s%"') do "%p%node\bin\node.exe" "%%i"
-goto :end
+rem Let cygpath try to convert this argument, if it fails the do clause won't be executed;
+rem if cygpath did not change the argument at all but only stripped quotes, we use the original argument.
+for /f "delims=:" %%i in ('%cmd_path%bin\cygpath -- %next_arg%') do if not "%~1"=="%%i" set next_arg="%%~i"
+
+rem Push the converted arg to the arg list
+set run=%run% %next_arg%
+
+rem Process next arg
+shift
+goto :loop
+
+rem End of argument list building loop
+:done
+
+rem Run node
+echo invoking %run%
+echo.
+%run%
-:end
echo.
echo node has exited.
pause
+rem Restore original environment
endlocal

0 comments on commit c70efc1

Please sign in to comment.