[前][次][番号順一覧][スレッド一覧]

ruby-changes:64728

From: Nobuyoshi <ko1@a...>
Date: Mon, 4 Jan 2021 16:38:05 +0900 (JST)
Subject: [ruby-changes:64728] 977252421b (master): ifchange: check the number of arguments

https://git.ruby-lang.org/ruby.git/commit/?id=977252421b

From 977252421baac7a4b42a914c48bc7ae29ec934ee Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Mon, 4 Jan 2021 14:31:18 +0900
Subject: ifchange: check the number of arguments


diff --git a/tool/ifchange b/tool/ifchange
index 050c8d8..5af41e0 100755
--- a/tool/ifchange
+++ b/tool/ifchange
@@ -3,6 +3,18 @@ https://github.com/ruby/ruby/blob/trunk/tool/ifchange#L3
 
 # Used in generating revision.h via Makefiles.
 
+help() {
+    cat <<HELP
+usage: $0 [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.
+HELP
+}
+
 set -e
 timestamp=
 keepsuffix=
@@ -10,6 +22,10 @@ empty= https://github.com/ruby/ruby/blob/trunk/tool/ifchange#L22
 color=auto
 until [ $# -eq 0 ]; do
     case "$1" in
+	--)
+	    shift
+	    break;
+	    ;;
 	--timestamp)
 	    timestamp=.
 	    ;;
@@ -34,6 +50,14 @@ until [ $# -eq 0 ]; do https://github.com/ruby/ruby/blob/trunk/tool/ifchange#L50
 	--debug)
 	    set -x
 	    ;;
+	--help)
+	    help
+	    exit
+	    ;;
+	--*)
+	    echo "$0: unknown option: $1" 1>&2
+	    exit 1
+	    ;;
 	*)
 	    break
 	    ;;
@@ -41,6 +65,11 @@ until [ $# -eq 0 ]; do https://github.com/ruby/ruby/blob/trunk/tool/ifchange#L65
     shift
 done
 
+if [ "$#" != 2 ]; then
+    help
+    exit 1
+fi
+
 target="$1"
 temp="$2"
 if [ "$temp" = - ]; then
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 @@ https://github.com/ruby/ruby/blob/trunk/win32/ifchange.bat#L1
 @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" ( https://github.com/ruby/ruby/blob/trunk/win32/ifchange.bat#L42
     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 https://github.com/ruby/ruby/blob/trunk/win32/ifchange.bat#L98
         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
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]