You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by do...@apache.org on 2020/04/16 19:55:25 UTC

[spark] branch master updated: [SPARK-31462][INFRA] The usage of getopts and case statement is wrong in do-release.sh

This is an automated email from the ASF dual-hosted git repository.

dongjoon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 2921be7  [SPARK-31462][INFRA] The usage of getopts and case statement is wrong in do-release.sh
2921be7 is described below

commit 2921be7a4e17b45591c25873a55fb286599b0fd7
Author: Kousuke Saruta <sa...@oss.nttdata.com>
AuthorDate: Thu Apr 16 12:54:10 2020 -0700

    [SPARK-31462][INFRA] The usage of getopts and case statement is wrong in do-release.sh
    
    ### What changes were proposed in this pull request?
    
    This PR (SPARK-31462) fixes the usage of getopts and case statement in `do-release.sh` and `do-release-docker.sh`.
    
    ### Why are the changes needed?
    
    In the current master, do-release.sh contains the following code.
    ```
    while getopts "bn" opt; do
      case $opt in
        b) GIT_BRANCH=$OPTARG ;;
        n) DRY_RUN=1 ;;
        ?) error "Invalid option: $OPTARG" ;;
      esac
    done
    ```
    There are 3 wrong usage in getopts and case statement.
    1. To set  $OPTARG to an argument passed for the option "b", the parameter for getopts should be "b:".
    2. To set $OPTARG to the invalid option name passed, the parameter for getopts starts with ":".
    3. It's minor but to match the character "?", it's better to escape like "\\?".
    
    ### Does this PR introduce any user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    I checked that $GIT_BRANCH is set when do-release.sh is launched with -b option.
    I also checked that the error message contains invalid option name when do-release.sh is launched with an invalid option.
    
    Closes #28234 from sarutak/fix-do-release.
    
    Authored-by: Kousuke Saruta <sa...@oss.nttdata.com>
    Signed-off-by: Dongjoon Hyun <do...@apache.org>
---
 dev/create-release/do-release-docker.sh | 4 ++--
 dev/create-release/do-release.sh        | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/dev/create-release/do-release-docker.sh b/dev/create-release/do-release-docker.sh
index 4a003d7..2f794c0 100755
--- a/dev/create-release/do-release-docker.sh
+++ b/dev/create-release/do-release-docker.sh
@@ -54,7 +54,7 @@ WORKDIR=
 IMGTAG=latest
 JAVA=
 RELEASE_STEP=
-while getopts "d:hj:ns:t:" opt; do
+while getopts ":d:hj:ns:t:" opt; do
   case $opt in
     d) WORKDIR="$OPTARG" ;;
     n) DRY_RUN=1 ;;
@@ -62,7 +62,7 @@ while getopts "d:hj:ns:t:" opt; do
     j) JAVA="$OPTARG" ;;
     s) RELEASE_STEP="$OPTARG" ;;
     h) usage ;;
-    ?) error "Invalid option. Run with -h for help." ;;
+    \?) error "Invalid option. Run with -h for help." ;;
   esac
 done
 
diff --git a/dev/create-release/do-release.sh b/dev/create-release/do-release.sh
index f1d4f3a..4f18a55 100755
--- a/dev/create-release/do-release.sh
+++ b/dev/create-release/do-release.sh
@@ -20,11 +20,11 @@
 SELF=$(cd $(dirname $0) && pwd)
 . "$SELF/release-util.sh"
 
-while getopts "bn" opt; do
+while getopts ":b:n" opt; do
   case $opt in
     b) GIT_BRANCH=$OPTARG ;;
     n) DRY_RUN=1 ;;
-    ?) error "Invalid option: $OPTARG" ;;
+    \?) error "Invalid option: $OPTARG" ;;
   esac
 done
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org