qemu-block
[Top][All Lists]
Advanced

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

[Qemu-block] [PATCH] Add interactive mode to qemu-img command


From: John Arbuckle
Subject: [Qemu-block] [PATCH] Add interactive mode to qemu-img command
Date: Mon, 30 Jul 2018 15:14:47 -0400

Changes qemu-img so if the user runs it without any
arguments, it will walk the user thru making an image
file.

Signed-off-by: John Arbuckle <address@hidden>
---
 qemu-img.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 9b7506b8ae..aa3df3b431 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -4873,6 +4873,32 @@ out:
     return ret;
 }
 
+/* Guides the user on making an image file */
+static int interactive_mode()
+{
+    char format[100];
+    char size[100];
+    char name[1000];
+
+    printf("\nInteractive mode (Enter Control-C to cancel)\n");
+    printf("Please select a format (qcow, qcow2, raw, vdi, vhdx, vmdk, vpc): 
");
+    scanf("%100s", format);
+    printf("Please enter a size (e.g. 100M, 10G): ");
+    scanf("%100s", size);
+    printf("Please enter a name: ");
+    scanf("%1000s", name);
+
+    const char *arguments[] = {"create", "-f", format, name, size};
+    int arg_count = 5;
+    int return_value;
+    return_value = img_create(arg_count, (char **)arguments);
+    if (return_value == 0) {
+        printf("Done creating image file\n");
+    }
+
+    return return_value;
+}
+
 static const img_cmd_t img_cmds[] = {
 #define DEF(option, callback, arg_string)        \
     { option, callback },
@@ -4912,8 +4938,9 @@ int main(int argc, char **argv)
 
     module_call_init(MODULE_INIT_QOM);
     bdrv_init();
-    if (argc < 2) {
-        error_exit("Not enough arguments");
+
+    if (argc == 1) { /* If no arguments passed to qemu-img */
+        return interactive_mode();
     }
 
     qemu_add_opts(&qemu_object_opts);
-- 
2.14.3 (Apple Git-98)




reply via email to

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