From 33cb63365749e76f6996f2c1a45a5f38dee00450 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 22 Apr 2012 16:36:35 -0400 Subject: functions: align error output with GNU getopt_long Display the name of the program. Signed-off-by: Dave Reisner --- functions | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/functions b/functions index e116005..127a830 100644 --- a/functions +++ b/functions @@ -35,7 +35,7 @@ parseopts() { return 255 ;; *) # fail, ambiguous match - error "option '%s' is ambiguous; possibilities:%s" \ + printf "%s: option '%s' is ambiguous; possibilities:%s\n" "${0##*/}" \ "--$1" "$(printf " '%s'" "${longmatch[@]%:}")" return 254 ;; esac @@ -53,7 +53,7 @@ parseopts() { # option doesn't exist if [[ $shortopts != *$opt* ]]; then - error "invalid option '%s'" "$opt" + printf "%s: invalid option -- '%s'\n" "${0##*/}" "$opt" OPTRET=(--) return 1 fi @@ -72,7 +72,7 @@ parseopts() { break # parse failure else - error "option '%s' requires an argument" "-$opt" + printf "%s: option '%s' requires an argument\n" "${0##*/}" "-$opt" OPTRET=(--) return 1 fi @@ -85,7 +85,7 @@ parseopts() { case $? in 0) if [[ $optarg ]]; then - error "option '%s' does not allow an argument" "--$opt" + printf "%s: option '--%s' doesn't allow an argument\n" "${0##*/}" "$opt" OPTRET=(--) return 1 else @@ -104,7 +104,7 @@ parseopts() { OPTRET+=("--$opt" "$2" ) shift 2 else - error "option '%s' requires an argument" "--$opt" + printf "%s: option '--%s' requires an argument\n" "${0##*/}" "$opt" OPTRET=(--) return 1 fi @@ -116,12 +116,11 @@ parseopts() { return 1 ;; 255) - error "invalid option '%s'" "--$opt" + # parse failure + printf "%s: unrecognized option '%s'\n" "${0##*/}" "--$opt" OPTRET=(--) return 1 ;; - *) - error "internal error: invalid option in longopt array '%s'" "--$opt" esac ;; *) # non-option arg encountered, add it as a parameter -- cgit v1.2.3-24-g4f1b