* [PATCH v1] erofs-utils: introduce long parameter option
@ 2019-10-21 18:19 Li Guifu
2019-10-22 2:50 ` Gao Xiang
0 siblings, 1 reply; 5+ messages in thread
From: Li Guifu @ 2019-10-21 18:19 UTC (permalink / raw)
To: linux-erofs
From: Li Guifu <blucerlee@gmail.com>
Only --help|-h is uesed right now
Signed-off-by: Li Guifu <blucerlee@gmail.com>
---
mkfs/main.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/mkfs/main.c b/mkfs/main.c
index 71c81f5..f62b065 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -13,6 +13,8 @@
#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,10 +25,16 @@
#define EROFS_SUPER_END (EROFS_SUPER_OFFSET + sizeof(struct erofs_super_block))
+static struct option long_options[] = {
+ {"help", no_argument, 0, 'h'},
+ {0, 0, 0, 0},
+};
+
static void usage(void)
{
fprintf(stderr, "usage: [options] FILE DIRECTORY\n\n");
fprintf(stderr, "Generate erofs image from DIRECTORY to FILE, and [options] are:\n");
+ fprintf(stderr, " -h|--help print usage message then exit 0\n");
fprintf(stderr, " -zX[,Y] X=compressor (Y=compression level, optional)\n");
fprintf(stderr, " -d# set output message level to # (maximum 9)\n");
fprintf(stderr, " -x# set xattr tolerance to # (< 0, disable xattrs; default 2)\n");
@@ -95,8 +103,10 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
{
char *endptr;
int opt, i;
+ int option_index = 0;
- while ((opt = getopt(argc, argv, "d:x:z:E:T:")) != -1) {
+ while((opt = getopt_long(argc, argv, "d:z:E:T:h", long_options,
+ &option_index)) != -1) {
switch (opt) {
case 'z':
if (!optarg) {
@@ -146,6 +156,11 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
}
break;
+ case 'h':
+ case '?':
+ usage();
+ exit(0);
+
default: /* '?' */
return -EINVAL;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v1] erofs-utils: introduce long parameter option
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
0 siblings, 1 reply; 5+ messages in thread
From: Gao Xiang @ 2019-10-22 2:50 UTC (permalink / raw)
To: Li Guifu, Li Guifu; +Cc: linux-erofs
Hi Guifu,
On Tue, Oct 22, 2019 at 02:19:23AM +0800, Li Guifu wrote:
> From: Li Guifu <blucerlee@gmail.com>
>
> Only --help|-h is uesed right now
^
typo in the commit message.
>
> Signed-off-by: Li Guifu <blucerlee@gmail.com>
> ---
> mkfs/main.c | 17 ++++++++++++++++-
> 1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/mkfs/main.c b/mkfs/main.c
> index 71c81f5..f62b065 100644
> --- a/mkfs/main.c
> +++ b/mkfs/main.c
> @@ -13,6 +13,8 @@
> #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,10 +25,16 @@
>
> #define EROFS_SUPER_END (EROFS_SUPER_OFFSET + sizeof(struct erofs_super_block))
>
> +static struct option long_options[] = {
> + {"help", no_argument, 0, 'h'},
How about removing '-h' from help message?
Thus we can keep '-h' for later usage instead of just print messages.
like,
{"help", no_argument, 0, 1},
> + {0, 0, 0, 0},
> +};
> +
> static void usage(void)
> {
> fprintf(stderr, "usage: [options] FILE DIRECTORY\n\n");
> fprintf(stderr, "Generate erofs image from DIRECTORY to FILE, and [options] are:\n");
> + fprintf(stderr, " -h|--help print usage message then exit 0\n");
How about moving it to the last line with the following change?
"--help display this help and exit"
and can we merge all fprintf into one line?
> fprintf(stderr, " -zX[,Y] X=compressor (Y=compression level, optional)\n");
> fprintf(stderr, " -d# set output message level to # (maximum 9)\n");
> fprintf(stderr, " -x# set xattr tolerance to # (< 0, disable xattrs; default 2)\n");
> @@ -95,8 +103,10 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
> {
> char *endptr;
> int opt, i;
> + int option_index = 0;
>
> - while ((opt = getopt(argc, argv, "d:x:z:E:T:")) != -1) {
> + while((opt = getopt_long(argc, argv, "d:z:E:T:h", long_options,
while((opt = getopt_long(argc, argv, "d:z:E:T:", long_options,
> + &option_index)) != -1) {
> switch (opt) {
> case 'z':
> if (!optarg) {
> @@ -146,6 +156,11 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
> }
> break;
>
> + case 'h':
case 1:
> + case '?':
remove this line.
If you don't care, I can post a modified version here.
Thanks,
Gao Xiang
> + usage();
> + exit(0);
> +
> default: /* '?' */
> return -EINVAL;
> }
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] erofs-utils: introduce long parameter option
2019-10-22 2:50 ` Gao Xiang
@ 2019-10-22 4:10 ` Gao Xiang
2019-10-22 15:51 ` Li Guifu
0 siblings, 1 reply; 5+ messages in thread
From: Gao Xiang @ 2019-10-22 4:10 UTC (permalink / raw)
To: Li Guifu; +Cc: linux-erofs
From: Li Guifu <blucerlee@gmail.com>
Only long option "--help" is valid now.
Signed-off-by: Li Guifu <blucerlee@gmail.com>
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
---
changes since v1:
- update based on
https://lore.kernel.org/r/20191022025053.GA180717@architecture4/
mkfs/main.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/mkfs/main.c b/mkfs/main.c
index 71c81f59e5b6..d3ebc8f55bda 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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] erofs-utils: introduce long parameter option
2019-10-22 4:10 ` [PATCH v2] " Gao Xiang
@ 2019-10-22 15:51 ` Li Guifu
2019-10-22 17:25 ` [PATCH v3] " Gao Xiang via Linux-erofs
0 siblings, 1 reply; 5+ messages in thread
From: Li Guifu @ 2019-10-22 15:51 UTC (permalink / raw)
To: Gao Xiang, Li Guifu; +Cc: linux-erofs
On 2019/10/22 12:10, Gao Xiang wrote:
> From: Li Guifu <blucerlee@gmail.com>
>
> Only long option "--help" is valid now.
>
> Signed-off-by: Li Guifu <blucerlee@gmail.com>
> Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
> ---
It looks good
Tested-by: Li Guifu <blucerlee@gmail.com>
Thanks,
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3] erofs-utils: introduce long parameter option
2019-10-22 15:51 ` Li Guifu
@ 2019-10-22 17:25 ` Gao Xiang via Linux-erofs
0 siblings, 0 replies; 5+ messages in thread
From: Gao Xiang via Linux-erofs @ 2019-10-22 17:25 UTC (permalink / raw)
To: Li Guifu, linux-erofs; +Cc: Miao Xie
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-10-22 17:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH v3] " Gao Xiang via Linux-erofs
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.