[PATCH 1/2] dim: Push the setup check down after alias resolution

Daniel Vetter daniel.vetter at ffwll.ch
Tue Nov 28 10:55:09 UTC 2017


I want to add more here.

Also fix an issue where you could never see the usage hint if you
typed the wrong subcommand without setup being done yet.

Signed-off-by: Daniel Vetter <daniel.vetter at intel.com>
---
 dim | 140 ++++++++++++++++++++++++++++++++++----------------------------------
 1 file changed, 70 insertions(+), 70 deletions(-)

diff --git a/dim b/dim
index ce0c7fa1ad42..283ae882f113 100755
--- a/dim
+++ b/dim
@@ -157,76 +157,6 @@ function pause
 	echo
 }
 
-#
-# Command line options.
-#
-
-DRY_RUN=
-INTERACTIVE=
-DRY=
-FORCE=
-HELP=
-
-while getopts hdfis opt; do
-	case "$opt" in
-		d)
-			DRY_RUN=--dry-run
-			DRY=echo
-			;;
-		f)
-			FORCE=1
-			;;
-		i)
-			INTERACTIVE=pause
-			;;
-		h)
-			HELP=1
-			;;
-		s)
-			# FIXME: transitional, do unconditionally at the top
-			# when there are no more errors about unbound variables
-			set -u
-			;;
-		*)
-			echoerr "See '$dim help' for more information."
-			exit
-	esac
-done
-shift $((OPTIND - 1))
-
-# first positional argument is the subcommand
-if [ -n "$HELP" ] || [ "$#" = "0" ]; then
-    subcommand="usage"
-else
-    subcommand="$1"
-    shift
-fi
-
-# generic usage to be used for ${1:?$usage} style argument references
-usage="Missing arguments(s) for '$dim $subcommand'. See '$dim help' for usage."
-
-#
-# Sanity checks.
-#
-
-# Make sure we use 'dim_foo' within dim instead of 'dim foo'.
-if [[ -n "${__dim_running:-}" ]]; then
-	echoerr "INTERNAL ERROR: do not recurse back to dim"
-	exit 1
-fi
-export __dim_running=1
-
-if [ "$subcommand" != "setup" ] && [ "$subcommand" != "help" ] && [ "$subcommand" != "usage" ]; then
-	for d in $DIM_PREFIX $DIM_PREFIX/$DIM_REPO $DIM_PREFIX/drm-rerere $DIM_PREFIX/drm-tip; do
-		if [ ! -d $d ]; then
-			echoerr "$d is missing, please check your configuration and/or run dim setup"
-			exit 1
-		fi
-	done
-
-	read_integration_config
-fi
-
 #
 # Only function and alias definitions until the subcommand handling at the end.
 #
@@ -2126,12 +2056,71 @@ function dim_usage
 # occasional check for dim updates
 check_for_updates
 
+#
+# Command line options.
+#
+
+DRY_RUN=
+INTERACTIVE=
+DRY=
+FORCE=
+HELP=
+
+while getopts hdfis opt; do
+	case "$opt" in
+		d)
+			DRY_RUN=--dry-run
+			DRY=echo
+			;;
+		f)
+			FORCE=1
+			;;
+		i)
+			INTERACTIVE=pause
+			;;
+		h)
+			HELP=1
+			;;
+		s)
+			# FIXME: transitional, do unconditionally at the top
+			# when there are no more errors about unbound variables
+			set -u
+			;;
+		*)
+			echoerr "See '$dim help' for more information."
+			exit
+	esac
+done
+shift $((OPTIND - 1))
+
+# first positional argument is the subcommand
+if [ -n "$HELP" ] || [ "$#" = "0" ]; then
+    subcommand="usage"
+else
+    subcommand="$1"
+    shift
+fi
+
+# generic usage to be used for ${1:?$usage} style argument references
+usage="Missing arguments(s) for '$dim $subcommand'. See '$dim help' for usage."
+
 # dim subcommand aliases (with bash 4.3+)
 if ! declare -n subcmd=dim_alias_${subcommand//-/_} &> /dev/null || \
 		test -z "${subcmd:-}"; then
 	subcmd="$subcommand"
 fi
 
+#
+# Sanity checks.
+#
+
+# Make sure we use 'dim_foo' within dim instead of 'dim foo'.
+if [[ -n "${__dim_running:-}" ]]; then
+	echoerr "INTERNAL ERROR: do not recurse back to dim"
+	exit 1
+fi
+export __dim_running=1
+
 # look up the function by the subcommand name
 subcmd_func=dim_${subcmd//-/_}
 if ! declare -f $subcmd_func >/dev/null; then
@@ -2140,6 +2129,17 @@ if ! declare -f $subcmd_func >/dev/null; then
 	exit 1
 fi
 
+if [ "$subcmd" != "setup" ] && [ "$subcmd" != "help" ] && [ "$subcmd" != "usage" ]; then
+	for d in $DIM_PREFIX $DIM_PREFIX/$DIM_REPO $DIM_PREFIX/drm-rerere $DIM_PREFIX/drm-tip; do
+		if [ ! -d $d ]; then
+			echoerr "$d is missing, please check your configuration and/or run dim setup"
+			exit 1
+		fi
+	done
+
+	read_integration_config
+fi
+
 # throw away to not confuse list-aliases
 unset subcmd
 
-- 
2.15.0



More information about the dim-tools mailing list