Skip to contentSkip to conversation

compat-drivers: Use case instead of if/if/.. blocks

PATCH In review Ozan Çağlayan 1 participant 2 messages Aug 16, 2012 – Aug 21, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 compat-drivers: Use case instead of if/if/.. blocks

case is much cleaner both for reading and for extending.

---
 scripts/admin-update.sh | 71 ++++++++++++++++++++++++++-----------------------
 1 file changed, 37 insertions(+), 34 deletions(-)
scripts/admin-update.sh +37 -34
index 22365cd..69b5287 100755
@@ -205,41 +205,44 @@ if [ $# -ge 1 ]; then
 		usage $0
 		exit
 	fi
-	if [[ $1 = "-h" || $1 = "--help" ]]; then
-		usage $0
-		exit
-	fi
 	while [ $# -ne 0 ]; do
-		if [[ "$1" = "-s" ]]; then
-			GET_STABLE_PENDING="y"
-			EXTRA_PATCHES="${EXTRA_PATCHES} pending-stable" 
-			EXTRA_PATCHES="${EXTRA_PATCHES} pending-stable/backports/"
-			POSTFIX_RELEASE_TAG="${POSTFIX_RELEASE_TAG}s"
-			shift; continue;
-		fi
-		if [[ "$1" = "-n" ]]; then
-			EXTRA_PATCHES="${EXTRA_PATCHES} linux-next-cherry-picks"
-			POSTFIX_RELEASE_TAG="${POSTFIX_RELEASE_TAG}n"
-			shift; continue;
-		fi
-		if [[ "$1" = "-p" ]]; then
-			EXTRA_PATCHES="${EXTRA_PATCHES} linux-next-pending"
-			POSTFIX_RELEASE_TAG="${POSTFIX_RELEASE_TAG}p"
-			shift; continue;
-		fi
-		if [[ "$1" = "-c" ]]; then
-			EXTRA_PATCHES="${EXTRA_PATCHES} crap"
-			POSTFIX_RELEASE_TAG="${POSTFIX_RELEASE_TAG}c"
-			shift; continue;
-		fi
-		if [[ "$1" = "refresh" ]]; then
-			REFRESH="y"
-			shift; continue;
-		fi
-
-		echo "Unexpected argument passed: $1"
-		usage $0
-		exit
+		case $1 in
+			"-s")
+				GET_STABLE_PENDING="y"
+				EXTRA_PATCHES="${EXTRA_PATCHES} pending-stable"
+				EXTRA_PATCHES="${EXTRA_PATCHES} pending-stable/backports/"
+				POSTFIX_RELEASE_TAG="${POSTFIX_RELEASE_TAG}s"
+				shift
+				;;
+			"-n")
+				EXTRA_PATCHES="${EXTRA_PATCHES} linux-next-cherry-picks"
+				POSTFIX_RELEASE_TAG="${POSTFIX_RELEASE_TAG}n"
+				shift
+				;;
+			"-p")
+				EXTRA_PATCHES="${EXTRA_PATCHES} linux-next-pending"
+				POSTFIX_RELEASE_TAG="${POSTFIX_RELEASE_TAG}p"
+				shift
+				;;
+			"-c")
+				EXTRA_PATCHES="${EXTRA_PATCHES} crap"
+				POSTFIX_RELEASE_TAG="${POSTFIX_RELEASE_TAG}c"
+				shift
+				;;
+			"refresh")
+				REFRESH="y"
+				shift
+				;;
+			"-h" | "--help")
+				usage $0
+				exit
+				;;
+			*)
+				echo "Unexpected argument passed: $1"
+				usage $0
+				exit
+				;;
+		esac
 	done
 
 fi
Signature · 1 line
1.7.11.2
#1 lore raw
Quoted 6 lines · Ozan Çağlayan

case is much cleaner both for reading and for extending.

---
 scripts/admin-update.sh | 71 ++++++++++++++++++++++++++-----------------------
 1 file changed, 37 insertions(+), 34 deletions(-)

Did you miss this?

Signature · 1 line
Ozan Çağlayan