diff mbox

[maintainer-tools,v2,31/33] dim: abstract dim_help

Message ID 9c0c69667f39c93ab34d5527af944b7166fc0e2e.1453985388.git.jani.nikula@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jani Nikula Jan. 28, 2016, 1:27 p.m. UTC
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@intel.com>
---
 dim | 50 ++++++++++++++++++++++++--------------------------
 1 file changed, 24 insertions(+), 26 deletions(-)
diff mbox

Patch

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