[PATCH v1] erofs-utils: introduce long parameter option
Li Guifu
wylgf01 at 163.com
Tue Oct 22 05:19:23 AEDT 2019
From: Li Guifu <blucerlee at gmail.com>
Only --help|-h is uesed right now
Signed-off-by: Li Guifu <blucerlee at 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
More information about the Linux-erofs
mailing list