Przeglądaj źródła

Switch usage errors to not print entire --help output

Just print a reference to use --help for further details. Which stops
annoying experienced users, or users that made a typo on the
command-line, by not overwhelming them with screenfuls of help output.

Closes: #681371
Guillem Jover 14 lat temu
rodzic
commit
cb674d55c4

+ 2 - 0
debian/changelog

@@ -104,6 +104,8 @@ dpkg (1.17.0) UNRELEASED; urgency=low
     gives a correct exit code. Thanks to Bernhard R. Link <brlink@debian.org>.
   * Print correct error message on unknown dpkg-name options before --.
   * Require at least one filename on dpkg-name after --.
+  * Switch program usage errors to not print entire --help output.
+    Closes: #681371
 
   [ Updated programs translations ]
   * Fix typo in Spanish translation of update-alternatives.

+ 3 - 2
scripts/Dpkg/ErrorHandling.pm

@@ -97,14 +97,15 @@ sub subprocerr(@)
     }
 }
 
+my $printforhelp = _g('Use --help for program usage information.');
+
 sub usageerr(@)
 {
     my ($msg) = (shift);
 
     $msg = sprintf($msg, @_) if (@_);
     warn "$Dpkg::PROGNAME: $msg\n\n";
-    # XXX: access to main namespace
-    main::usage();
+    warn "$printforhelp\n";
     exit(2);
 }
 

+ 8 - 11
scripts/dpkg-maintscript-helper.sh

@@ -39,7 +39,7 @@ rm_conffile() {
 	fi
 	# Skip remaining parameters up to --
 	while [ "$1" != "--" -a $# -gt 0 ]; do shift; done
-	[ $# -gt 0 ] || badusage
+	[ $# -gt 0 ] || badusage "missing arguments after --"
 	shift
 
 	[ -n "$PACKAGE" ] || error "couldn't identify the package"
@@ -142,7 +142,7 @@ mv_conffile() {
 	fi
 	# Skip remaining parameters up to --
 	while [ "$1" != "--" -a $# -gt 0 ]; do shift; done
-	[ $# -gt 0 ] || badusage
+	[ $# -gt 0 ] || badusage "missing arguments after --"
 	shift
 
 	[ -n "$PACKAGE" ] || error "couldn't identify the package"
@@ -250,7 +250,9 @@ END
 }
 
 badusage() {
-	usage
+	echo "$PROGNAME: error: $1" >&2
+	echo >&2
+	echo "Use '$PROGNAME help' for program usage information." >&2
 	exit 1
 }
 
@@ -260,7 +262,7 @@ set -e
 PROGNAME=$(basename $0)
 version="unknown"
 command="$1"
-[ $# -gt 0 ] || badusage
+[ $# -gt 0 ] || badusage "missing command"
 shift
 
 case "$command" in
@@ -301,13 +303,8 @@ mv_conffile)
 	END
 	;;
 *)
-	cat >&2 <<-END
-	$PROGNAME: error: command $command is unknown
-	Hint: upgrading dpkg to a newer version might help.
-
-	END
-	usage
-	exit 1
+	badusage "command $command is unknown
+Hint: upgrading dpkg to a newer version might help."
 esac
 
 exit 0

+ 6 - 4
scripts/dpkg-mergechangelogs.pl

@@ -85,11 +85,13 @@ my @options_spec = (
 }
 
 my ($old, $new_a, $new_b, $out_file) = @ARGV;
-unless (defined $old and defined $new_a and defined $new_b and
-        -e $old and -e $new_a and -e $new_b)
+unless (defined $old and defined $new_a and defined $new_b)
 {
-    usage();
-    exit(2);
+    usageerr(_g('needs at least three arguments'));
+}
+unless (-e $old and -e $new_a and -e $new_b)
+{
+    usageerr(_g('file arguments need to exist'));
 }
 
 my ($cho, $cha, $chb);

+ 3 - 1
utils/update-alternatives.c

@@ -173,7 +173,9 @@ badusage(char const *fmt, ...)
 	vfprintf(stderr, fmt, args);
 	va_end(args);
 	fprintf(stderr, "\n\n");
-	usage();
+	fprintf(stderr, _("Use '%s --help' for program usage information."),
+	        PROGNAME);
+	fprintf(stderr, "\n");
 	exit(2);
 }