[Libguestfs] [PATCH 3/3] fish: improve the command error messages
Richard W.M. Jones
rjones at redhat.com
Thu Dec 5 15:58:42 UTC 2013
On Thu, Dec 05, 2013 at 04:30:06PM +0100, Pino Toscano wrote:
> - when a command needs no parameters, tell that explicitly instead of
> "command should have 0 parameters"
> - use gettext's plural form when printing the number of required
> arguments
> - improve the error message for a variable number of parameters limited
> only in the maximum number of them, using also a plural form
> ---
> generator/fish.ml | 20 ++++++++++++++++----
> 1 file changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/generator/fish.ml b/generator/fish.ml
> index 65f1acb..da0584b 100644
> --- a/generator/fish.ml
> +++ b/generator/fish.ml
> @@ -362,12 +362,24 @@ Guestfish will prompt for these separately."
>
> if argc_minimum = argc_maximum then (
> pr " if (argc != %d) {\n" argc_minimum;
> - pr " fprintf (stderr, _(\"%%s should have %%d parameter(s)\\n\"), cmd, %d);\n"
> - argc_minimum;
> + if argc_minimum = 0 then (
> + pr " fprintf (stderr, _(\"%%s should have no parameters\\n\"), cmd);\n";
> + ) else (
> + pr " fprintf (stderr, ngettext(\"%%s should have %%d parameter\\n\",\n";
> + pr " \"%%s should have %%d parameters\\n\",\n";
> + pr " %d),\n"
> + argc_minimum;
> + pr " cmd, %d);\n"
> + argc_minimum;
> + )
> ) else if argc_minimum = 0 then (
> pr " if (argc > %d) {\n" argc_maximum;
> - pr " fprintf (stderr, _(\"%%s should have %%d-%%d parameter(s)\\n\"), cmd, %d, %d);\n"
> - argc_minimum argc_maximum;
> + pr " fprintf (stderr, ngettext(\"%%s should have at most %%d parameter\\n\",\n";
> + pr " \"%%s should have at most %%d parameters\\n\",\n";
> + pr " %d),\n"
> + argc_maximum;
> + pr " cmd, %d);\n"
> + argc_maximum;
> ) else (
> pr " if (argc < %d || argc > %d) {\n" argc_minimum argc_maximum;
> pr " fprintf (stderr, _(\"%%s should have %%d-%%d parameter(s)\\n\"), cmd, %d, %d);\n"
> --
> 1.8.3.1
ACK.
I tested this with various combinations of commands:
$ ./run ./fish/guestfish version foo
version should have no parameters
type 'help version' for help on version
$ ./run ./fish/guestfish set-qemu foo bar
set-qemu should have 1 parameter
type 'help set-qemu' for help on set-qemu
$ ./run ./fish/guestfish set-qemu foo bar baz
set-qemu should have 1 parameter
type 'help set-qemu' for help on set-qemu
$ ./run ./fish/guestfish lvcreate foo
lvcreate should have 3 parameters
type 'help lvcreate' for help on lvcreate
$ ./run ./fish/guestfish umount-local foo bar
umount-local should have at most 1 parameter
type 'help umount-local' for help on umount-local
[Apparently only umount-local uses the argc > argc_maximum case]
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
More information about the Libguestfs
mailing list