summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-01-04 14:31:18 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-01-04 15:54:09 +0900
commit977252421baac7a4b42a914c48bc7ae29ec934ee (patch)
tree144bcd9d2deac90ee4041e1f99c0b1969a06544d /win32
parent8da7f4abc779c6549833d718336d75aac98494b8 (diff)
ifchange: check the number of arguments
Diffstat (limited to 'win32')
-rwxr-xr-xwin32/ifchange.bat30
1 files changed, 28 insertions, 2 deletions
diff --git a/win32/ifchange.bat b/win32/ifchange.bat
index 606d6ed..c7db628 100755
--- a/win32/ifchange.bat
+++ b/win32/ifchange.bat
@@ -1,13 +1,16 @@
@echo off
:: usage: ifchange target temporary
+for %%I in (%0) do set progname=%%~nI
set timestamp=
set keepsuffix=
set empty=
set color=auto
:optloop
for %%I in (%1) do set opt=%%~I
-if "%opt%" == "--timestamp" (
+if "%opt%" == "--" (
+ shift
+) else if "%opt%" == "--timestamp" (
set timestamp=.
shift
goto :optloop
@@ -39,8 +42,18 @@ if "%opt%" == "--timestamp" (
shift
echo on
goto :optloop
+) else if "%opt%" == "--help" (
+ call :help
+ exit /b
+) else if "%opt:~0,2%" == "--" (
+ echo %progname%: unknown option: %1 1>&2
+ exit /b 1
+)
+
+if "%2" == "" (
+ call :help 1>&2
+ exit /b 1
)
-if "%opt%" == "" goto :end
set dest=%1
set src=%2
@@ -85,4 +98,17 @@ if "%timestamp%" == "" goto :end
for %%I in ("%dest%") do set timestamp=%%~dpI.time.%%~nxI
)
goto :end > "%timestamp%"
+
+:help
+ for %%I in (
+ "usage: %progname% [options] target new-file"
+ "options:"
+ " --timestamp[=file] touch timestamp file. (default: prefixed with '.time')"
+ " under the directory of the target)"
+ " --keep[=suffix] keep old file with suffix. (default: '.old')"
+ " --empty assume unchanged if the new file is empty."
+ " --color[=always|auto|never] colorize output."
+ ) do echo.%%~I
+ goto :eof
+
:end