From 3d6fb20968457c7a343df4fd1bd17b87a2449475 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sun, 21 Apr 2019 19:55:16 +0200 Subject: Implement options verbose quiet dry-run help. --- localrmstaleaccounts | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/localrmstaleaccounts b/localrmstaleaccounts index b6e9a05..dbb92f0 100755 --- a/localrmstaleaccounts +++ b/localrmstaleaccounts @@ -2,21 +2,52 @@ set -e +PRG=$(basename "$0") + exit1() { echo >&2 "ERROR: $1" exit 1 } +TEMP=$(getopt -s sh -o vqnh --long verbose,quiet,dry-run,help -n "$PRG" -- "$@") || exit1 "Internal getopt error" +eval set -- "$TEMP" + +usage() { + cat <&2 +Usage: $PRG [opts...] USER [USER...] + + -v, --verbose increase verbosity + -q, --quiet suppress non-error messages + -n, --dry-run perform a trial run with no changes made + -h, --help show this help +EOF + exit 0 +} + +VERBOSE= +QUIET= +DRY_RUN= +while true ; do + case "$1" in + -v|--verbose) VERBOSE=1; shift;; + -q|--quiet) QUIET=1; shift;; + -n|--dry-run) DRY_RUN=1; shift;; + -h|--help) usage;; + --) shift; break;; + *) exit1 "Internal getopt parsing error";; + esac +done + warn() { - echo >&2 "WARNING: $1" + [ -n "$QUIET" ] || echo >&2 "WARNING: $1" } info() { - echo >&2 "INFO: $1" + [ -n "$QUIET" ] || [ -z "$VERBOSE" ] || echo >&2 "INFO: $1" } remove_account() { - localrmaccount "$1" + [ -n "$DRY_RUN" ] || localrmaccount "$1" } for user in $@; do -- cgit v1.2.3