From 300d702540224d1b739e06f0b4efda0bc428807c Mon Sep 17 00:00:00 2001 From: Ruediger Meier Date: Wed, 21 Jun 2017 22:37:37 +0200 Subject: [PATCH] mkfs.cramfs: add --help and --version Note, we were already using errtryhelp() without providing a --help option. Signed-off-by: Ruediger Meier --- disk-utils/mkfs.cramfs.8 | 8 ++++---- disk-utils/mkfs.cramfs.c | 34 +++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/disk-utils/mkfs.cramfs.8 b/disk-utils/mkfs.cramfs.8 index c2e843ab9..9701e1075 100644 --- a/disk-utils/mkfs.cramfs.8 +++ b/disk-utils/mkfs.cramfs.8 @@ -64,11 +64,11 @@ sorting. \fB\-z\fR Make explicit holes. Use of this option will require 2.3.39 kernel, or newer. .TP -\fB\-V\fR -Display version information and exit. +\fB\-h\fR, \fB\-\-help\fR +Display help text and exit. .TP -\fB\-h\fR -Display help and exit. +\fB\-V\fR, \fB\-\-version\fR +Display version information and exit. .SH "EXIT STATUS" .RS .PD 0 diff --git a/disk-utils/mkfs.cramfs.c b/disk-utils/mkfs.cramfs.c index 77b4467e7..87b378c81 100644 --- a/disk-utils/mkfs.cramfs.c +++ b/disk-utils/mkfs.cramfs.c @@ -122,15 +122,11 @@ struct entry { #define CRAMFS_GID_WIDTH 8 #define CRAMFS_OFFSET_WIDTH 26 -/* Input status of 0 to print help and exit without an error. */ -static void __attribute__((__noreturn__)) -usage(int status) { - FILE *stream = status ? stderr : stdout; - - fprintf(stream, +static void __attribute__((__noreturn__)) usage(void) +{ + printf( _("usage: %s [-h] [-v] [-b blksize] [-e edition] [-N endian] [-i file] " "[-n name] dirname outfile\n" - " -h print this help\n" " -v be verbose\n" " -E make all warnings errors " "(non-zero exit status)\n" @@ -147,7 +143,11 @@ usage(int status) { " outfile output file\n"), program_invocation_short_name, PAD_SIZE); - exit(status); + fputs(USAGE_SEPARATOR, stdout); + fputs(USAGE_HELP, stdout); + fputs(USAGE_VERSION, stdout); + printf(USAGE_MAN_TAIL("mkfs.cramfs(8)")); + exit(MKFS_EX_OK); } static char * @@ -717,11 +717,21 @@ int main(int argc, char **argv) textdomain(PACKAGE); atexit(close_stdout); + if (argc > 1) { + /* first arg may be one of our standard longopts */ + if (!strcmp(argv[1], "--help")) + usage(); + if (!strcmp(argv[1], "--version")) { + printf(UTIL_LINUX_VERSION); + exit(MKFS_EX_OK); + } + } + /* command line options */ while ((c = getopt(argc, argv, "hb:Ee:i:n:N:psVvz")) != EOF) { switch (c) { case 'h': - usage(MKFS_EX_OK); + usage(); case 'b': blksize = strtou32_or_err(optarg, _("invalid blocksize argument")); break; @@ -773,8 +783,10 @@ int main(int argc, char **argv) } } - if ((argc - optind) != 2) - usage(MKFS_EX_USAGE); + if ((argc - optind) != 2) { + warnx(_("bad usage")); + errtryhelp(MKFS_EX_USAGE); + } dirname = argv[optind]; outfile = argv[optind + 1];