Re: [Libguestfs] [PATCH] fish: show synopsis if command syntax is wrong

Hu Tao
Mon, 01 Dec 2014 02:25:51 -0000

On Fri, Nov 28, 2014 at 03:00:39PM +0100, Pino Toscano
wrote:
> 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.

fish commands do not have args and optargs in their definitions in file
actions.ml. Also, fish commands' synopsises are printed out by inline
codes, see run_alloc() for an example.

Surely we can reconstruct fish commands' definitions to take advantage
of the auto-generation of synopsis done in this patch, but that can be
another patch. I'll add this to my todo list.

>
> > @@ -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.

Thanks, both fixed.

Regards,
Hu

>
> --
> Pino Toscano
>
> _______________________________________________
> Libguestfs mailing list
> Libguestfs@redhat.com
> https://www.redhat.com/mailman/listinfo/libguestfs