[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]