[maintainer-tools PATCH v2 32/33] dim: show usage instead of the man page on unknown subcommands

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

 



I find displaying the man page on every typo a bit distracting. Now that
we can list all the supported subcommands (by way of listing all the
dim_ prefixed functions), add usage to show quick help. Also make it a
subcommand of its own.

Signed-off-by: Jani Nikula <jani.nikula@xxxxxxxxx>
---
 dim | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/dim b/dim
index 6f50f8b67184..1651b5e8218a 100755
--- a/dim
+++ b/dim
@@ -139,7 +139,7 @@ shift `expr $OPTIND - 1`
 
 # first positional argument is the subcommand
 if [ "$#" = "0" ]; then
-    subcommand="help"
+    subcommand="usage"
 else
     subcommand="$1"
     shift
@@ -149,7 +149,7 @@ fi
 # Sanity checks.
 #
 
-if [ "$subcommand" != "setup" -a "$subcommand" != "help" ]; then
+if [ "$subcommand" != "setup" -a "$subcommand" != "help" -a "$subcommand" != "usage" ]; then
 	for d in $DIM_PREFIX $DIM_PREFIX/$DIM_DRM_INTEL $DIM_PREFIX/drm-intel-rerere $DIM_PREFIX/drm-intel-nightly; do
 		if [ ! -d $d ]; then
 			echo "$d is missing, please check your configuration and/or run dim setup"
@@ -1096,6 +1096,16 @@ function dim_help
 	$renderer < $manpage | $pager
 }
 
+function dim_usage
+{
+	echo "usage: $0 [OPTIONS] SUBCOMMAND [ARGUMENTS]"
+	echo
+	echo "The available subcommands are:"
+	declare -F | grep -o " dim_[a-zA-Z_]*" | sed 's/^ dim_/\t/'
+	echo
+	echo "See '$0 help' for more information."
+}
+
 # dim subcommand aliases
 declare -n subcmd=dim_alias_${subcommand//-/_}
 if [ -z "$subcmd" ]; then
@@ -1107,5 +1117,6 @@ subcmd_func=dim_${subcmd//-/_}
 if declare -f $subcmd_func >/dev/null; then
 	$subcmd_func "$@"
 else
-	dim_help
+	echo "$0: '$subcommand' is not a dim command." >&2
+	dim_usage
 fi
-- 
2.1.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux