Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Improved argument parsing for node.cmd

  • Loading branch information...
commit c70efc15e703e3b7f2db151e99dc78864f8439c7 1 parent de92b10
Bert Belder authored August 04, 2010

Showing 1 changed file with 38 additions and 10 deletions. Show diff stats Hide diff stats

  1. 48  resource/node.cmd
48  resource/node.cmd
... ...
@@ -1,21 +1,49 @@
1 1
 @echo off
  2
+
  3
+rem Keep changes to the environment within this script
2 4
 setlocal
3 5
 
4  
-set p=%~dp0
5  
-set s=%~f1
6  
-set path=%p%bin\;%path%
  6
+rem Path to this script
  7
+set cmd_path=%~dp0
  8
+
  9
+rem Set path to cygwin binutils
  10
+set path=%cmd_path%bin\;%cmd_path%node\bin;%path%
  11
+
  12
+rem Start building the node command
  13
+set run="%cmd_path%node\bin\node.exe"
  14
+
  15
+rem For each command line argument, try to convert to a cygwin path
  16
+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
  17
+:loop
  18
+
  19
+rem Test if there are more arguments to convert
  20
+if %1.==. goto :done
7 21
 
8  
-if not "%s%"=="" goto :script
9  
-"%p%node\bin\node.exe"
10  
-goto :end
  22
+rem Fetch the next argument
  23
+set next_arg=%1
11 24
 
12  
-:script
13  
-for /f "delims=:" %%i in ('cygpath "%s%"') do "%p%node\bin\node.exe" "%%i"
14  
-goto :end
  25
+rem Let cygpath try to convert this argument, if it fails the do clause won't be executed;
  26
+rem if cygpath did not change the argument at all but only stripped quotes, we use the original argument.
  27
+for /f "delims=:" %%i in ('%cmd_path%bin\cygpath -- %next_arg%') do if not "%~1"=="%%i" set next_arg="%%~i"
  28
+
  29
+rem Push the converted arg to the arg list
  30
+set run=%run% %next_arg%
  31
+
  32
+rem Process next arg
  33
+shift
  34
+goto :loop
  35
+
  36
+rem End of argument list building loop
  37
+:done
  38
+
  39
+rem Run node
  40
+echo invoking %run%
  41
+echo.
  42
+%run%
15 43
 
16  
-:end
17 44
 echo.
18 45
 echo node has exited.
19 46
 pause
20 47
 
  48
+rem Restore original environment
21 49
 endlocal

0 notes on commit c70efc1

Please sign in to comment.
Something went wrong with that request. Please try again.