From: John Arbuckle <programmingkidx@gmail.com>
To: qemu-devel@nongnu.org
Cc: John Arbuckle <programmingkidx@gmail.com>
Subject: [Qemu-devel] [PATCH] Add interactive mode to qemu-img command
Date: Mon, 30 Jul 2018 15:29:55 -0400 [thread overview]
Message-ID: <20180730192955.14291-1-programmingkidx@gmail.com> (raw)
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 <programmingkidx@gmail.com>
---
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)
next reply other threads:[~2018-07-30 19:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-30 19:29 John Arbuckle [this message]
2018-07-31 1:52 ` [Qemu-devel] [PATCH] Add interactive mode to qemu-img command no-reply
2018-07-31 2:15 ` no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180730192955.14291-1-programmingkidx@gmail.com \
--to=programmingkidx@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.