savannah-hackers-public
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Savannah-hackers-public] [PATCH 1/2] Add getopt command-line parsing


From: Bruno Félix Rezende Ribeiro
Subject: [Savannah-hackers-public] [PATCH 1/2] Add getopt command-line parsing
Date: Sat, 26 Sep 2015 04:49:35 -0300

---
 gsv-eval-remote.sh | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/gsv-eval-remote.sh b/gsv-eval-remote.sh
index 1a9b105..55cfb07 100755
--- a/gsv-eval-remote.sh
+++ b/gsv-eval-remote.sh
@@ -49,7 +49,7 @@ Will download SOURCE-URL, run the gnu-savannal evaluation 
perl script
 on the download files, and produce an HTML file named OUTPUT-HTML.
 
 Options:
- -h              = show this help screen.
+ -h, --help              = show this help screen.
 
 Examples:
 
@@ -163,11 +163,17 @@ process_package() {
     esac
 }
 
-test "x$1" = "x-h" && usage
+GETOPT=$(getopt -oh -lhelp -n $(basename "$0") -- "$@") \
+  || { echo "error: cannot parse command line" >&2; exit 1; }
+eval set -- "$GETOPT"
 
-OUTPUT_HTML=$(realpath $1)
-PROJECT_NAME=$2
-SOURCE=$3
+while [ $1 != "--" ]; do
+    case "$1" in
+       -h|--help) usage;;
+       *) echo "error: getopt inconsistency --- report this bug!"; exit 1;;
+    esac
+done
+shift
 
 test -z "$OUTPUT_HTML" \
     && die "missing OUTPUT-HTML parameter. See -h for help."
@@ -178,6 +184,9 @@ test -z "$SOURCE" \
 touch "$OUTPUT_HTML" \
     || die "failed to create output file '$OUTPUT_HTML'"
 
+OUTPUT_HTML=$(realpath $1)
+PROJECT_NAME=$2
+SOURCE=$3
 
 ## From here on, we can at least log the errors into the output HTML file
 OUTPUT_FILE="$OUTPUT_HTML"
-- 
2.1.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]