From patchwork Mon Jul 30 19:29:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 10549599 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9132E14E0 for ; Mon, 30 Jul 2018 19:30:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79ABC2A755 for ; Mon, 30 Jul 2018 19:30:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E47C2A78D; Mon, 30 Jul 2018 19:30:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EE9542A755 for ; Mon, 30 Jul 2018 19:30:47 +0000 (UTC) Received: from localhost ([::1]:55532 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fkDsV-0006SC-6r for patchwork-qemu-devel@patchwork.kernel.org; Mon, 30 Jul 2018 15:30:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47255) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fkDrv-00064p-Em for qemu-devel@nongnu.org; Mon, 30 Jul 2018 15:30:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fkDrs-00037O-QH for qemu-devel@nongnu.org; Mon, 30 Jul 2018 15:30:11 -0400 Received: from mail-io0-x244.google.com ([2607:f8b0:4001:c06::244]:37806) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fkDrs-00037B-L3 for qemu-devel@nongnu.org; Mon, 30 Jul 2018 15:30:08 -0400 Received: by mail-io0-x244.google.com with SMTP id z19-v6so10855472ioh.4 for ; Mon, 30 Jul 2018 12:30:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ZAuNHAlsvlH4Cl7z2PyhX9H5xzPhkfsBGkUDzRN9Rqc=; b=Z03FZVOPQcaCzmlCdoicFAKgB6zMTBhUYrFrBg76R4GurHyieN0rfCIDH8hFmBDmOw z+CN+0K9Siy3HXCM0WniJb610V0P5JeQV6TXFsmAchtE4rPjsjJ7tkoJjfdXvVWFfebq cj53Qih+4rtvKVaxsCNA2/GjEkSg1PLB9bf3KRsbzqu5gkvj1BqOFw10Mdk8EtAxDOSx mXU8BD+AnmgCN8FydwVoEkWdVFT35uqN15wug5eW5a5BvT1PgvZkEEcXlUey+QTOReFH y5pcL6QBgd0RFcz57ZlVnIJQoVymbBKZn/yQZruXrhHzfjvf9s6oNKCPQS+k9s8JC74c 1vvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ZAuNHAlsvlH4Cl7z2PyhX9H5xzPhkfsBGkUDzRN9Rqc=; b=rHq/Tuw+ClzR8Lrzt5sVtGSlqM3KVpHgyo1m7fsvVOst6ULvbN3dIK/Q2dSbdpNM+B YO9w98i5KV65DFl3Kcc4Cejpp3oEWjYExbQHVSAlw/Ofuqo7r4AkGaNtlHMt8T6yg4Xi ggg4r1uzDafKTs+DGIjE7d8+mdOz/E20YKb3vKYH1v31d7wW28d5djDhQddyYLztf4nG 6vlLVlJ7GAhpp9s5EngzisOQrqByUUmCHkk8QcNN6ayX4W7yCgpbArL3fV+sg5BGtPG4 Ho0os6jNKwSF9ZsBZwouQmqR7sQsc6eDBx8kOy5r15TqI9HPBQJbLSNyIeB2qhCkvKXe gSRg== X-Gm-Message-State: AOUpUlHJk/qSnOdeCyOgGkdokAYh5MNtoDpYpdKaiR6WLYsztzJgbDVO i5tFgLt2pgtEnjnk+oJJtvF/y42O X-Google-Smtp-Source: AAOMgpdsW4x1Kdm6JAoS4a0j7B2uI+T5qgFA8TAYqjBkBiHNLd11rHqmobKYULgrizjORV5L01t5xg== X-Received: by 2002:a6b:dc0e:: with SMTP id s14-v6mr13805319ioc.226.1532979007810; Mon, 30 Jul 2018 12:30:07 -0700 (PDT) Received: from localhost.localdomain ([69.14.184.20]) by smtp.gmail.com with ESMTPSA id p145-v6sm5048310iod.23.2018.07.30.12.30.06 (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 30 Jul 2018 12:30:06 -0700 (PDT) From: John Arbuckle To: qemu-devel@nongnu.org Date: Mon, 30 Jul 2018 15:29:55 -0400 Message-Id: <20180730192955.14291-1-programmingkidx@gmail.com> X-Mailer: git-send-email 2.14.3 (Apple Git-98) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c06::244 Subject: [Qemu-devel] [PATCH] Add interactive mode to qemu-img command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Arbuckle Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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);