qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/8] qemu-img: refresh options/--help for "create" subcommand


From: Michael Tokarev
Subject: [PATCH 2/8] qemu-img: refresh options/--help for "create" subcommand
Date: Wed, 7 Feb 2024 20:58:11 +0300

Add missing long options (eg --format).

Create helper function cmd_help() to display command-specific
help text, and use it to print --help for create.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
 qemu-img.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/qemu-img.c b/qemu-img.c
index a634747701..b94622fadb 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -126,6 +126,16 @@ void unrecognized_option(const char *cmdname, const char 
*option)
     error_exit(cmdname, "unrecognized option '%s'", option);
 }
 
+static G_NORETURN
+void cmd_help(const char *cmdname, const char *syntax,
+              const char *description, const char *arguments)
+{
+    printf("qemu-img %s %s\n%s.\n"
+           " -h|--help - print this help and exit\n%s",
+           cmdname, syntax, description, arguments);
+    exit(EXIT_SUCCESS);
+}
+
 /* Please keep in synch with docs/tools/qemu-img.rst */
 static G_NORETURN
 void help(void)
@@ -524,7 +534,13 @@ static int img_create(const char *cmdname, int argc, char 
**argv)
     for(;;) {
         static const struct option long_options[] = {
             {"help", no_argument, 0, 'h'},
+            {"quiet", no_argument, 0, 'q'},
             {"object", required_argument, 0, OPTION_OBJECT},
+            {"format", required_argument, 0, 'f'},
+            {"backing", required_argument, 0, 'b'},
+            {"backing-format", required_argument, 0, 'F'},
+            {"backing-unsafe", no_argument, 0, 'u'},
+            {"options", required_argument, 0, 'o'},
             {0, 0, 0, 0}
         };
         c = getopt_long(argc, argv, ":F:b:f:ho:qu",
@@ -540,7 +556,22 @@ static int img_create(const char *cmdname, int argc, char 
**argv)
             unrecognized_option(cmdname, argv[optind - 1]);
             break;
         case 'h':
-            help();
+            cmd_help(cmdname, "[OPTIONS] FILE [SIZE[bkKMGTPE]]",
+                     "Creates and initializes a new image",
+" -q|--quiet - quiet operations\n"
+" -f|--format FMT - specifies format of the new image, default is raw\n"
+" -o|--options FMT_OPTS - format-specific options ('-o list' for list)\n"
+" -b|--backing BACKING_IMG - stack new image on top of BACKING_IMG\n"
+"  (for formats which support stacking)\n"
+" -F|--backing-format BACKING_FMT - specify format of BACKING_IMG\n"
+" -u|--backing-unsafe - do not fail if BACKING_FMT can not be read\n"
+" --object OBJDEF - QEMU user-creatable object (eg encryption key)\n"
+" FILE - image file to create. FILE will be overriden if exists\n"
+" SIZE - image size with optional suffix: 'b' (byte, default),\n"
+"  'k' or 'K' (kilobyte, *1024), 'M' (megabyte, *1024K), 'G' (gigabyte, 
*1024M),\n"
+"  'T' (terabyte, *1024G), 'P' (petabyte, *1024T), or 'E' (exabyte, *1024P)\n"
+"  SIZE is required unless BACKING_IMG is specified, in which case\n"
+"  it will be the same as size of BACKING_IMG\n");
             break;
         case 'F':
             base_fmt = optarg;
-- 
2.39.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]