[Libguestfs] [PATCH 3/3] fish: improve the command error messages

Pino Toscano ptoscano at redhat.com
Thu Dec 5 15:30:06 UTC 2013


- 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




More information about the Libguestfs mailing list