[Libguestfs] [PATCH] v2v: Make the interface between cmdline.ml and v2v.ml

Richard W.M. Jones rjones at redhat.com
Tue Nov 10 20:00:56 UTC 2015


I'm interested to hear opinions on whether this makes the code
clearer, or not.

This is virt-v2v, but many other virt-* tools work the same way, and
analogous changes could be made.

Currently when command line argument parsing is done in 'cmdline.ml'
the list of parsed parameters is passed to the main program in a very
long tuple.  Each parameter is strongly typed, but not named (so for
example two 'bool' flags on the command line might be swapped
accidentally).

This patch uses a struct to pass the parameters instead, so they are
both strongly typed *and* named - two parameters with the same type
could not be swapped by accident.

Also the type of each parameter is now defined in the struct 'type'
definition, which also appears in a 'cmdline.mli' file.

In addition, in the main program it should be clearer where a
particular variable comes from, ie. you have to write
'cmdline.output_alloc' instead of 'output_alloc', which may make it
clearer that it comes from the command line '-oa' parameter, thus
making the code easier to understand.

Rich.




More information about the Libguestfs mailing list