Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/etcupdate etcupdate: add -? for help. improve optio...



details:   https://anonhg.NetBSD.org/src/rev/8e6e96cf44b5
branches:  trunk
changeset: 359542:8e6e96cf44b5
user:      lukem <lukem%NetBSD.org@localhost>
date:      Sun Jan 09 03:33:26 2022 +0000

description:
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.

diffstat:

 usr.sbin/etcupdate/etcupdate   |  34 ++++++++++++++++++++++++++--------
 usr.sbin/etcupdate/etcupdate.8 |   8 +++++---
 2 files changed, 31 insertions(+), 11 deletions(-)

diffs (115 lines):

diff -r 26881a468354 -r 8e6e96cf44b5 usr.sbin/etcupdate/etcupdate
--- a/usr.sbin/etcupdate/etcupdate      Sun Jan 09 03:31:23 2022 +0000
+++ b/usr.sbin/etcupdate/etcupdate      Sun Jan 09 03:33:26 2022 +0000
@@ -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 @@
        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 @@
                               "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 @@
 [ -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 @@
        w)
                WIDTH="${OPTARG}"
                ;;
+       "?")
+               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
+               ;;
+
        *)
-               # getopts should already have printed an error message
-               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 @@
 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
diff -r 26881a468354 -r 8e6e96cf44b5 usr.sbin/etcupdate/etcupdate.8
--- a/usr.sbin/etcupdate/etcupdate.8    Sun Jan 09 03:31:23 2022 +0000
+++ b/usr.sbin/etcupdate/etcupdate.8    Sun Jan 09 03:33:26 2022 +0000
@@ -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 @@
 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



Home | Main Index | Thread Index | Old Index