On Thu, Nov 08, 2018 at 03:29:51PM -0600, Eric Blake wrote:
Our use of --tls is a superset of boolean because we add a force mode; but once we have checked for that, it's more consistent if we accept the same set of other boolean values as anything else (in this case, adding 'yes/no' and 'true/false'), as well as consistently allowing case-insensitivity. The error message for an unrecognized spelling changes from:
$ nbdkit --tls huh nbdkit: --tls flag must be off|on|require
to:
$ nbdkit --tls huh nbdkit: error: could not decipher boolean (huh)
but I don't think that hurts too much.
Signed-off-by: Eric Blake <eblake@redhat.com> ---
src/main.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/src/main.c b/src/main.c index 7ebbba6..0a883e1 100644 --- a/src/main.c +++ b/src/main.c @@ -376,18 +376,14 @@ main (int argc, char *argv[])
case TLS_OPTION: tls_set_on_cli = 1; - if (strcmp (optarg, "off") == 0 || strcmp (optarg, "0") == 0) - tls = 0; - else if (strcmp (optarg, "on") == 0 || strcmp (optarg, "1") == 0) - tls = 1; - else if (strcmp (optarg, "require") == 0 || - strcmp (optarg, "required") == 0 || - strcmp (optarg, "force") == 0) + if (strcasecmp (optarg, "require") == 0 || + strcasecmp (optarg, "required") == 0 || + strcasecmp (optarg, "force") == 0) tls = 2; else { - fprintf (stderr, "%s: --tls flag must be off|on|require\n", - program_name); - exit (EXIT_FAILURE); + tls = nbdkit_parse_bool (optarg); + if (tls < 0)
Stylisticly I guess we use tls == -1 elsewhere, but it's not a big deal. Rich.
+ exit (EXIT_FAILURE); } break;
-- 2.17.2
_______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://www.redhat.com/mailman/listinfo/libguestfs
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html