[Intel-gfx] [maintainer-tools PATCH v2 31/33] dim: abstract dim_help

Jani Nikula jani.nikula at intel.com
Thu Jan 28 05:27:25 PST 2016


dim help being the last subcommand handled by the switch case,
obliterate it as well, finishing the job we set out to do. Now all
subcommands are handled via dim_ prefixed functions.

Signed-off-by: Jani Nikula <jani.nikula at intel.com>
---
 dim | 50 ++++++++++++++++++++++++--------------------------
 1 file changed, 24 insertions(+), 26 deletions(-)

diff --git a/dim b/dim
index 4370aec28ec0..6f50f8b67184 100755
--- a/dim
+++ b/dim
@@ -1074,6 +1074,28 @@ function dim_fixes
 		sed -e 's/\([0-f]\{12\}\)[0-f]*/\1/'
 }
 
+function dim_help
+{
+	manpage=$DIM_PREFIX/maintainer-tools/dim.rst
+	if [ ! -e "$manpage" ]; then
+		manpage=$(dirname $(readlink -f $0))/dim.rst
+		if [ ! -e "$manpage" ]; then
+			echo "Can't find the man page. See http://cgit.freedesktop.org/drm-intel/tree/dim.rst?h=maintainer-tools"
+			exit 1
+		fi
+	fi
+
+	if hash rst2man 2>/dev/null; then
+		renderer=rst2man
+		pager="man -l -"
+	else
+		renderer=cat
+		pager=${PAGER:-cat}
+	fi
+
+	$renderer < $manpage | $pager
+}
+
 # dim subcommand aliases
 declare -n subcmd=dim_alias_${subcommand//-/_}
 if [ -z "$subcmd" ]; then
@@ -1084,30 +1106,6 @@ fi
 subcmd_func=dim_${subcmd//-/_}
 if declare -f $subcmd_func >/dev/null; then
 	$subcmd_func "$@"
-	exit 0
+else
+	dim_help
 fi
-
-# XXX: abscract each case to a dim_ prefixed function, and turn the help|*) case
-# into an else branch in the above check for functions.
-case "$subcmd" in
-	help|*)
-		manpage=$DIM_PREFIX/maintainer-tools/dim.rst
-		if [ ! -e "$manpage" ]; then
-			manpage=$(dirname $(readlink -f $0))/dim.rst
-			if [ ! -e "$manpage" ]; then
-				echo "Can't find the man page. See http://cgit.freedesktop.org/drm-intel/tree/dim.rst?h=maintainer-tools"
-				exit 1
-			fi
-		fi
-
-		if hash rst2man 2>/dev/null; then
-			renderer=rst2man
-			pager="man -l -"
-		else
-			renderer=cat
-			pager=${PAGER:-cat}
-		fi
-
-		$renderer < $manpage | $pager
-		;;
-esac
-- 
2.1.4



More information about the Intel-gfx mailing list