Module Name:    src
Committed By:   lukem
Date:           Sun Jan  9 03:33:26 UTC 2022

Modified Files:
        src/usr.sbin/etcupdate: etcupdate etcupdate.8

Log Message:
etcupdate: add -? for help. improve option errors

Support -? to show help.
Implemented using getopts "leading colon optstring" feature.
Improve error messages for unknown options and missing arguments.
Change usage-related errors from stdout to stderr.
Keep all other errors to stdout for now.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/usr.sbin/etcupdate/etcupdate
cvs rdiff -u -r1.24 -r1.25 src/usr.sbin/etcupdate/etcupdate.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/etcupdate/etcupdate
diff -u src/usr.sbin/etcupdate/etcupdate:1.63 src/usr.sbin/etcupdate/etcupdate:1.64
--- src/usr.sbin/etcupdate/etcupdate:1.63	Sun Jan  9 03:31:23 2022
+++ src/usr.sbin/etcupdate/etcupdate	Sun Jan  9 03:33:26 2022
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: etcupdate,v 1.63 2022/01/09 03:31:23 lukem Exp $
+# $NetBSD: etcupdate,v 1.64 2022/01/09 03:33:26 lukem Exp $
 #
 # Copyright (c) 2001-2022 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -85,7 +85,7 @@ help()
 	cat << EOF
 
 Usage: ${PROG} [-alv] [-d DESTDIR] [-p PAGER] [-s SRC_ARG] [-t TEMPROOT] [-w WIDTH]
-       ${PROG} -h
+       ${PROG} ( -h | -? )
 
 Options:
 
@@ -103,10 +103,10 @@ Options:
                               "etc.tgz" and "xetc.tgz" have been extracted.
                  -s TGZ_FILE  A distribution set file such as "etc.tgz" or
                               "xetc.tgz".  May be specified multiple times.
-
   -t TEMPROOT  Where to store temporary files. [/tmp/temproot]
   -w WIDTH     Screen width.                   [80]
   -v           Be more verbose.
+  -?           Display this help, and exit.
 
 EOF
 }
@@ -477,7 +477,7 @@ USERRC="${HOME}/.{PROG}rc"
 [ -r ${USERRC} ] && . ${USERRC}
 
 # Read command line arguments
-while getopts ad:hlp:s:t:vw: i
+while getopts :ad:hlp:s:t:vw: i
 do
 	case "${i}" in
 	a)
@@ -539,13 +539,31 @@ do
 	w)
 		WIDTH="${OPTARG}"
 		;;
-	*)
-		# getopts should already have printed an error message
+	"?")
+		if [ "${OPTARG}" = "?" ]; then
+			help
+			exit 0
+		fi
+		echo 1>&2 "${PROG}: Unknown option -${OPTARG}"
+		usage
+		;;
+
+	:)
+		echo 1>&2 "${PROG}: Missing argument for option -${OPTARG}"
 		usage
-		break
+		;;
+
+	*)
+		echo 1>&2 "${PROG}: Unimplemented option -${ch}"
+		exit 3
 		;;
 	esac
 done
+shift $((${OPTIND} - 1))
+if [ $# -ne 0 ] ; then
+	echo 1>&2 "${PROG}: Unknown extra arguments"
+	usage
+fi
 
 # Last minute sanity checks
 if [ "$(id -u)" -ne 0 ]; then
@@ -555,7 +573,7 @@ fi
 DESTDIR="${DESTDIR%/}" # remove trailing slash, if any.  result might be "".
 DESTDIR_BRE="$(bre_quote "${DESTDIR}")"
 if [ "${N_SRC_ARGS}" -gt 1 ] && ( ${SOURCEMODE} || ${BINARYDIRMODE} ); then
-	echo "*** ERROR: Multiple -s args are allowed only with tgz files"
+	echo 1>&2 "${PROG}: Multiple -s args are allowed only with tgz files"
 	usage
 fi
 case "${TEMPROOT}" in

Index: src/usr.sbin/etcupdate/etcupdate.8
diff -u src/usr.sbin/etcupdate/etcupdate.8:1.24 src/usr.sbin/etcupdate/etcupdate.8:1.25
--- src/usr.sbin/etcupdate/etcupdate.8:1.24	Sun Jan  9 03:31:23 2022
+++ src/usr.sbin/etcupdate/etcupdate.8	Sun Jan  9 03:33:26 2022
@@ -1,6 +1,6 @@
-.\"	$NetBSD: etcupdate.8,v 1.24 2022/01/09 03:31:23 lukem Exp $
+.\"	$NetBSD: etcupdate.8,v 1.25 2022/01/09 03:33:26 lukem Exp $
 .\"
-.\" Copyright (c) 2001-2020 The NetBSD Foundation, Inc.
+.\" Copyright (c) 2001-2022 The NetBSD Foundation, Inc.
 .\" All rights reserved.
 .\"
 .\" This code is derived from software contributed to The NetBSD Foundation
@@ -43,7 +43,7 @@
 .Op Fl t Ar temproot
 .Op Fl w Ar width
 .Nm
-.Fl h
+.Pq Fl h | Fl \&?
 .Sh DESCRIPTION
 .Nm
 is a tool that lets the administrator update the configuration and
@@ -280,6 +280,8 @@ variable.
 This is useful for
 .Xr xterm 1
 users with wider shell windows.
+.It Fl \&?
+Prints a help text, and exit.
 .El
 .Sh ENVIRONMENT
 .Bl -tag -width IGNOREFILESXX

Reply via email to