On Friday 28 November 2014 17:55:51 Hu Tao wrote:
> This patch lets guestfish show command synopsis if the syntax of command 
> issued
> by user is wrong, rather than telling user that the number of parameters is 
> wrong.

The idea seems sound to me.

Shouldn't that be done also for fish commands? If so, just make
"synopsis" a function taking args and optargs, and use it in both
places.

> @@ -694,10 +679,16 @@ Guestfish will prompt for these separately."
>    pr "run_action (const char *cmd, size_t argc, char *argv[])\n";
>    pr "{\n";
>    pr "  const struct command_table *ct;\n";
> +  pr "  int ret = -1;\n";
>    pr "\n";
>    pr "  ct = lookup_fish_command (cmd, strlen (cmd));\n";
> -  pr "  if (ct)\n";
> -  pr "    return ct->entry->run (cmd, argc, argv);\n";
> +  pr "  if (ct) {\n";
> +  pr "    ret = ct->entry->run (cmd, argc, argv);\n";
> +  pr "    if (ret == -2) {\n";
> +  pr "      fprintf (stderr, _(\"usage: %%s\\n\"), ct->entry->synopsis);\n";
> +  pr "      fprintf (stderr, _(\"type 'help %%s' for more help on %%s\\n\"), 
> cmd, cmd);\n";
> +  pr "    }\n";
> +  pr "  }\n";

There is an issue here: in the true branch of "if (ct)", there is no
more return, and thus builds fails when enabling -Werror
(--enable-werror for configure):

cmds.c: In function 'run_action':
cmds.c:23233:1: error: control reaches end of non-void function 
[-Werror=return-type]
 }
 ^

Also, the return code -2 must be turned as -1.

-- 
Pino Toscano

_______________________________________________
Libguestfs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libguestfs

Reply via email to