Hu Tao
2014-Dec-01 02:25 UTC
Re: [Libguestfs] [PATCH] fish: show synopsis if command syntax is wrong
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
Hu Tao
2014-Dec-01 06:42 UTC
Re: [Libguestfs] [PATCH] fish: show synopsis if command syntax is wrong
On Mon, Dec 01, 2014 at 10:25:51AM +0800, Hu Tao wrote:> 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.After some dig, the only problem I don't know how to solve is commands with variable-length parameters, such as copy-in. Its synopsis is: copy-in local [local ...] /remotedir At first think its style could be: "style = RErr, [StringList "local"], []; But it seems the syntax corresponding to StringList is: copy-in "local local" /remotedir e.g. its a one parameter of List type, but not several parameters. Any ideas? Regards, Hu
Richard W.M. Jones
2014-Dec-01 09:44 UTC
Re: [Libguestfs] [PATCH] fish: show synopsis if command syntax is wrong
On Mon, Dec 01, 2014 at 02:42:54PM +0800, Hu Tao wrote:> On Mon, Dec 01, 2014 at 10:25:51AM +0800, Hu Tao wrote: > > 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. > > After some dig, the only problem I don't know how to solve is commands > with variable-length parameters, such as copy-in. Its synopsis is: > > copy-in local [local ...] /remotedir > > At first think its style could be: > > "style = RErr, [StringList "local"], []; > > But it seems the syntax corresponding to StringList is: > > copy-in "local local" /remotedir > > e.g. its a one parameter of List type, but not several parameters. Any > ideas?As you've discovered, guestfish commands don't use the 'style' field at all. Each command receives an argc/argv list of strings and parses it however it wants to. It's not restricted by the usual rules for other API functions and so can use variable length lists of arguments. So there is no way to get from the struct in actions.ml to a synopsis. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Possibly Parallel Threads
- Re: [PATCH] fish: show synopsis if command syntax is wrong
- Re: [PATCH] fish: show synopsis if command syntax is wrong
- [PATCH] fish: show synopsis if command syntax is wrong
- Re: [PATCH v2] fish: show synopsis if command syntax is wrong
- Re: [PATCH] fish: show synopsis if command syntax is wrong