erofs-utils: have each non-fuse command take -h, --help, -V, and --version
authorLuke T. Shumaker <lukeshu@umorpha.io>
Thu, 2 Nov 2023 19:31:20 +0000 (13:31 -0600)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Mon, 6 Nov 2023 05:41:09 +0000 (13:41 +0800)
Consistency is nice.

erofsfuse isn't included here because adjusting its flag handling is
more involved because of the interaction with libfuse; I anticipate
similar changes to erofsfuse in a future patchset.

Signed-off-by: Luke T. Shumaker <lukeshu@umorpha.io>
Link: https://lore.kernel.org/r/20231102193122.140921-2-lukeshu@lukeshu.com
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
dump/main.c
fsck/main.c
man/dump.erofs.1
man/fsck.erofs.1
man/mkfs.erofs.1
mkfs/main.c

index 5425b7bd890feb0df50e9f4d22c1160232137e99..a952f32ad9178627b22254b8ec73cf4eedd71e73 100644 (file)
@@ -74,7 +74,8 @@ struct erofs_statistics {
 static struct erofs_statistics stats;
 
 static struct option long_options[] = {
-       {"help", no_argument, NULL, 1},
+       {"version", no_argument, NULL, 'V'},
+       {"help", no_argument, NULL, 'h'},
        {"nid", required_argument, NULL, 2},
        {"device", required_argument, NULL, 3},
        {"path", required_argument, NULL, 4},
@@ -110,14 +111,14 @@ static void usage(void)
        fputs("usage: [options] IMAGE\n\n"
              "Dump erofs layout from IMAGE, and [options] are:\n"
              " -S              show statistic information of the image\n"
-             " -V              print the version number of dump.erofs and exit.\n"
+             " -V, --version   print the version number of dump.erofs and exit.\n"
              " -e              show extent info (INODE required)\n"
              " -s              show information about superblock\n"
              " --device=X      specify an extra device to be used together\n"
              " --ls            show directory contents (INODE required)\n"
              " --nid=#         show the target inode info of nid #\n"
              " --path=X        show the target inode info of path X\n"
-             " --help          display this help and exit.\n",
+             " -h, --help      display this help and exit.\n",
              stderr);
 }
 
@@ -130,7 +131,7 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)
 {
        int opt, err;
 
-       while ((opt = getopt_long(argc, argv, "SVes",
+       while ((opt = getopt_long(argc, argv, "SVesh",
                                  long_options, NULL)) != -1) {
                switch (opt) {
                case 'e':
@@ -153,7 +154,7 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)
                        dumpcfg.nid = (erofs_nid_t)atoll(optarg);
                        ++dumpcfg.totalshow;
                        break;
-               case 1:
+               case 'h':
                        usage();
                        exit(0);
                case 3:
index 3f86da4bdd206bfb521bf71cd9d062558aa42892..2ac35470395ca511aff96ab8548653c8b52a16ec 100644 (file)
@@ -35,7 +35,8 @@ struct erofsfsck_cfg {
 static struct erofsfsck_cfg fsckcfg;
 
 static struct option long_options[] = {
-       {"help", no_argument, 0, 1},
+       {"version", no_argument, 0, 'V'},
+       {"help", no_argument, 0, 'h'},
        {"extract", optional_argument, 0, 2},
        {"device", required_argument, 0, 3},
        {"force", no_argument, 0, 4},
@@ -78,12 +79,12 @@ static void usage(void)
 {
        fputs("usage: [options] IMAGE\n\n"
              "Check erofs filesystem compatibility and integrity of IMAGE, and [options] are:\n"
-             " -V                     print the version number of fsck.erofs and exit\n"
+             " -V, --version          print the version number of fsck.erofs and exit\n"
              " -d#                    set output message level to # (maximum 9)\n"
              " -p                     print total compression ratio of all files\n"
              " --device=X             specify an extra device to be used together\n"
              " --extract[=X]          check if all files are well encoded, optionally extract to X\n"
-             " --help                 display this help and exit\n"
+             " -h, --help             display this help and exit\n"
              "\nExtraction options (--extract=X is required):\n"
              " --force                allow extracting to root\n"
              " --overwrite            overwrite files that already exist\n"
@@ -109,7 +110,7 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)
        int opt, ret;
        bool has_opt_preserve = false;
 
-       while ((opt = getopt_long(argc, argv, "Vd:p",
+       while ((opt = getopt_long(argc, argv, "Vd:ph",
                                  long_options, NULL)) != -1) {
                switch (opt) {
                case 'V':
@@ -126,7 +127,7 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)
                case 'p':
                        fsckcfg.print_comp_ratio = true;
                        break;
-               case 1:
+               case 'h':
                        usage();
                        exit(0);
                case 2:
index 7316f4bf7304aa6265f3bf39d3fe6b65e1ec7bd9..6237eade7dd67075b97639ec4770eff059b984c6 100644 (file)
@@ -45,9 +45,12 @@ or
 .I path
 required.
 .TP
-.BI \-V
+\fB\-V\fR, \fB\-\-version\fR
 Print the version number and exit.
 .TP
+\fB\-h\fR, \fB\-\-help\fR
+Display help string and exit.
+.TP
 .BI \-s
 Show superblock information.
 This is the default if no options are specified.
index 364219a2b20c636a219a964ac9d4d56d73506a11..a226995327e846096b4531472dfda4931f64faa9 100644 (file)
@@ -10,7 +10,7 @@ fsck.erofs is used to scan an EROFS filesystem \fIIMAGE\fR and check the
 integrity of it.
 .SH OPTIONS
 .TP
-.B \-V
+\fB\-V\fR, \fB\-\-version\fR
 Print the version number of fsck.erofs and exit.
 .TP
 .BI "\-d " #
@@ -32,7 +32,7 @@ Check if all files are well encoded. This read all compressed files,
 and hence create more I/O load,
 so it might take too much time depending on the image.
 .TP
-.B \-\-help
+\fB\-h\fR, \fB\-\-help\fR
 Display help string and exit.
 .SH AUTHOR
 This version of \fBfsck.erofs\fR is written by
index 00ac2ac9c03bfd4041d8f54906297f25ab9119e2..970ff281e8576d40074e9253615d2324757c9af4 100644 (file)
@@ -163,7 +163,10 @@ set to \fIGID\fR + \fIGID-OFFSET\fR.
 .B \-\-gzip
 Filter tarball streams through gzip.
 .TP
-.B \-\-help
+\fB\-V\fR, \fB\-\-version\fR
+Print the version number and exit.
+.TP
+\fB\-h\fR, \fB\-\-help\fR
 Display help string and exit.
 .TP
 .B "\-\-ignore-mtime"
index 637d1b9f07373288b476fa86185f3bde2b73660f..d86a548b2c31d06e62cd00c5f0a216cb7fb8c125 100644 (file)
@@ -34,7 +34,8 @@
 #define EROFS_SUPER_END (EROFS_SUPER_OFFSET + sizeof(struct erofs_super_block))
 
 static struct option long_options[] = {
-       {"help", no_argument, 0, 1},
+       {"version", no_argument, 0, 'V'},
+       {"help", no_argument, 0, 'h'},
        {"exclude-path", required_argument, NULL, 2},
        {"exclude-regex", required_argument, NULL, 3},
 #ifdef HAVE_LIBSELINUX
@@ -91,6 +92,7 @@ static void usage(void)
 {
        fputs("usage: [options] FILE SOURCE(s)\n"
              "Generate EROFS image (FILE) from DIRECTORY, TARBALL and/or EROFS images.  And [options] are:\n"
+             " -V, --version         print the version number of mkfs.erofs and exit\n"
              " -b#                   set block size to # (# = page size by default)\n"
              " -d#                   set output message level to # (maximum 9)\n"
              " -x#                   set xattr tolerance to # (< 0, disable xattrs; default 2)\n"
@@ -117,7 +119,7 @@ static void usage(void)
 #ifdef HAVE_ZLIB
              " --gzip                try to filter the tarball stream through gzip\n"
 #endif
-             " --help                display this help and exit\n"
+             " -h, --help            display this help and exit\n"
              " --ignore-mtime        use build time instead of strict per-file modification time\n"
              " --max-extent-bytes=#  set maximum decompressed extent size # in bytes\n"
              " --preserve-mtime      keep per-file modification time strictly\n"
@@ -141,6 +143,11 @@ static void usage(void)
        print_available_compressors(stderr, ", ");
 }
 
+static void version(void)
+{
+       printf("mkfs.erofs %s\n", cfg.c_version);
+}
+
 static unsigned int pclustersize_packed, pclustersize_max;
 static struct erofs_tarfile erofstar = {
        .global.xattrs = LIST_HEAD_INIT(erofstar.global.xattrs)
@@ -309,7 +316,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
        int opt, i, err;
        bool quiet = false;
 
-       while ((opt = getopt_long(argc, argv, "C:E:L:T:U:b:d:x:z:",
+       while ((opt = getopt_long(argc, argv, "C:E:L:T:U:b:d:x:z:Vh",
                                  long_options, NULL)) != -1) {
                switch (opt) {
                case 'z':
@@ -534,7 +541,10 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
                case 517:
                        gzip_supported = true;
                        break;
-               case 1:
+               case 'V':
+                       version();
+                       exit(0);
+               case 'h':
                        usage();
                        exit(0);