From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57188) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8qQt-000508-Dn for qemu-devel@nongnu.org; Fri, 03 Jun 2016 10:50:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8qQs-0008Hf-4H for qemu-devel@nongnu.org; Fri, 03 Jun 2016 10:50:43 -0400 References: <1464892545-26544-1-git-send-email-den@openvz.org> <1464892545-26544-5-git-send-email-den@openvz.org> From: Eric Blake Message-ID: <5751993B.5090909@redhat.com> Date: Fri, 3 Jun 2016 08:50:35 -0600 MIME-Version: 1.0 In-Reply-To: <1464892545-26544-5-git-send-email-den@openvz.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="uaCW7rKECOd0l2hh6gMPDIBnWmCJ9rx6F" Subject: Re: [Qemu-devel] [PATCH 4/5] qemu-img: move common options parsing before commands processing List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Denis V. Lunev" , qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: Paolo Bonzini , Stefan Hajnoczi , Kevin Wolf This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --uaCW7rKECOd0l2hh6gMPDIBnWmCJ9rx6F Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 06/02/2016 12:35 PM, Denis V. Lunev wrote: > This is necessary to enable creation of common qemu-img options which w= ill > be specified before command. >=20 > Signed-off-by: Denis V. Lunev > CC: Eric Blake > CC: Paolo Bonzini > CC: Stefan Hajnoczi > CC: Kevin Wolf > --- > qemu-img.c | 31 +++++++++++++++++++------------ > 1 file changed, 19 insertions(+), 12 deletions(-) >=20 > - /* find the command */ > - for (cmd =3D img_cmds; cmd->name !=3D NULL; cmd++) { > - if (!strcmp(cmdname, cmd->name)) { > - return cmd->handler(argc - 1, argv + 1); > + while ((c =3D getopt_long(argc, argv, "+h", long_options, NULL)) != =3D -1) { > + switch (c) { > + case 'h': > + help(); > + return 0; > + case 'v': Umm, how is 'v' supposed to be hit if it is not passed in the short option string summary? That is, 'qemu-img --version' will work, but 'qemu-img -v' won't; while both 'qemu-img --help' and 'qemu-img -h' work.= > + printf(QEMU_IMG_VERSION); > + return 0; > } > } > =20 > - c =3D getopt_long(argc, argv, "h", long_options, NULL); > + cmdname =3D argv[optind]; > =20 > - if (c =3D=3D 'h') { > - help(); > - } > - if (c =3D=3D 'v') { On the other hand, it seems to be a pre-existing bug. Still, it's worth fixing while you're touching this. In addition to moving the option processing, you should also update the documentation (both --help and man page). --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --uaCW7rKECOd0l2hh6gMPDIBnWmCJ9rx6F Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJXUZk7AAoJEKeha0olJ0NqzuEIAI2b8BDjdJyJDYdPC6OGq+xe VvBTKprMNIgN/E1utnr3zeknjPPDXry5+kNGECl816hyErHoTvovTtR7L9fBVTJE n9vnSTFLo8DCuY1jxWXzQG53Q0x4mZxGmaRkmiIJ+Z7VIVw3d2DxafW5fFPUYKk5 oUFOqKAoXNxzNrZ6LMh1AMZvSibofnpWJzv9a3NUzifwI3irqwwCeL/8enC4L0eS RK1UlCLEa+MdfS5ZgzpGk/8Zccc4t25RZG7DDCDe82mlBZ0BAJN7PHSCZnFYJcjN fJOGoVsm9ognca+i5hsth02JpJsmXXZYY+ePmSNdOmizaYbkZCCZNPkSjXAcE5Y= =FYls -----END PGP SIGNATURE----- --uaCW7rKECOd0l2hh6gMPDIBnWmCJ9rx6F--