linux-erofs.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Gao Xiang via Linux-erofs <linux-erofs@lists.ozlabs.org>
To: Li Guifu <bluce.liguifu@huawei.com>, linux-erofs@lists.ozlabs.org
Cc: Miao Xie <miaoxie@huawei.com>
Subject: [PATCH v3] erofs-utils: introduce long parameter option
Date: Wed, 23 Oct 2019 01:25:18 +0800	[thread overview]
Message-ID: <20191022172518.9020-1-hsiangkao@aol.com> (raw)
In-Reply-To: <e920ef02-6ec8-cce3-504d-2405b2178f08@gmail.com>

From: Li Guifu <blucerlee@gmail.com>

Only long option "--help" is valid now.

Signed-off-by: Li Guifu <blucerlee@gmail.com>
Tested-by: Li Guifu <blucerlee@gmail.com>
Signed-off-by: Gao Xiang <hsiangkao@aol.com>
---
changes since v2:
 - add getopt.h to AC_CHECK_HEADERS;

 configure.ac |  1 +
 mkfs/main.c  | 14 +++++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 8c31cb7..4f88678 100644
--- a/configure.ac
+++ b/configure.ac
@@ -71,6 +71,7 @@ AC_ARG_VAR([LZ4_LIBS], [linker flags for lz4])
 AC_CHECK_HEADERS(m4_flatten([
 	dirent.h
 	fcntl.h
+	getopt.h
 	inttypes.h
 	linux/falloc.h
 	linux/fs.h
diff --git a/mkfs/main.c b/mkfs/main.c
index 71c81f5..31cf1c2 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -13,6 +13,7 @@
 #include <limits.h>
 #include <libgen.h>
 #include <sys/stat.h>
+#include <getopt.h>
 #include "erofs/config.h"
 #include "erofs/print.h"
 #include "erofs/cache.h"
@@ -23,6 +24,11 @@
 
 #define EROFS_SUPER_END (EROFS_SUPER_OFFSET + sizeof(struct erofs_super_block))
 
+static struct option long_options[] = {
+	{"help", no_argument, 0, 1},
+	{0, 0, 0, 0},
+};
+
 static void usage(void)
 {
 	fprintf(stderr, "usage: [options] FILE DIRECTORY\n\n");
@@ -32,6 +38,7 @@ static void usage(void)
 	fprintf(stderr, " -x#       set xattr tolerance to # (< 0, disable xattrs; default 2)\n");
 	fprintf(stderr, " -EX[,...] X=extended options\n");
 	fprintf(stderr, " -T#       set a fixed UNIX timestamp # to all files\n");
+	fprintf(stderr, " --help    display this help and exit\n");
 }
 
 static int parse_extended_opts(const char *opts)
@@ -96,7 +103,8 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 	char *endptr;
 	int opt, i;
 
-	while ((opt = getopt(argc, argv, "d:x:z:E:T:")) != -1) {
+	while((opt = getopt_long(argc, argv, "d:x:z:E:T:",
+				 long_options, NULL)) != -1) {
 		switch (opt) {
 		case 'z':
 			if (!optarg) {
@@ -146,6 +154,10 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 			}
 			break;
 
+		case 1:
+			usage();
+			exit(0);
+
 		default: /* '?' */
 			return -EINVAL;
 		}
-- 
2.17.1


      reply	other threads:[~2019-10-22 17:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-21 18:19 [PATCH v1] erofs-utils: introduce long parameter option Li Guifu
2019-10-22  2:50 ` Gao Xiang
2019-10-22  4:10   ` [PATCH v2] " Gao Xiang
2019-10-22 15:51     ` Li Guifu
2019-10-22 17:25       ` Gao Xiang via Linux-erofs [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191022172518.9020-1-hsiangkao@aol.com \
    --to=linux-erofs@lists.ozlabs.org \
    --cc=bluce.liguifu@huawei.com \
    --cc=hsiangkao@aol.com \
    --cc=miaoxie@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).