Pino Toscano
2016-Jul-18 17:29 UTC
[Libguestfs] [PATCH 1/2] v2v: register also aliases of input/output modules
This makes them visible in the help text of -i and -o. --- v2v/input_disk.ml | 5 ++++- v2v/output_local.ml | 5 ++++- v2v/output_rhev.ml | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/v2v/input_disk.ml b/v2v/input_disk.ml index 17ad61d..508f16a 100644 --- a/v2v/input_disk.ml +++ b/v2v/input_disk.ml @@ -101,4 +101,7 @@ class input_disk input_format disk = object end let input_disk = new input_disk -let () = Modules_list.register_input_module "disk" +let () + Modules_list.register_input_module "disk"; + (* Alias *) + Modules_list.register_input_module "local" diff --git a/v2v/output_local.ml b/v2v/output_local.ml index 47da929..f2945ec 100644 --- a/v2v/output_local.ml +++ b/v2v/output_local.ml @@ -61,4 +61,7 @@ class output_local dir = object end let output_local = new output_local -let () = Modules_list.register_output_module "local" +let () + Modules_list.register_output_module "local"; + (* Alias *) + Modules_list.register_output_module "disk" diff --git a/v2v/output_rhev.ml b/v2v/output_rhev.ml index e45043b..bec5f44 100644 --- a/v2v/output_rhev.ml +++ b/v2v/output_rhev.ml @@ -282,4 +282,7 @@ object end let output_rhev = new output_rhev -let () = Modules_list.register_output_module "rhev" +let () + Modules_list.register_output_module "rhev"; + (* Alias *) + Modules_list.register_output_module "ovirt" -- 2.7.4
Pino Toscano
2016-Jul-18 17:29 UTC
[Libguestfs] [PATCH 2/2] v2v: use Getopt.Symbol for few options
Use Getopt.Symbol for options with a fixed list of choices, so there is no need to check them on our own. --- v2v/cmdline.ml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml index 2d0a10a..ddf5858 100644 --- a/v2v/cmdline.ml +++ b/v2v/cmdline.ml @@ -136,8 +136,7 @@ let parse_cmdline () match mode with | "sparse" -> output_alloc := `Sparse | "preallocated" -> output_alloc := `Preallocated - | s -> - error (f_"unknown -oa option: %s") s + | s -> assert false (* Already checked by Getopt.Symbol. *) in let root_choice = ref AskRoot in @@ -171,7 +170,7 @@ let parse_cmdline () [ L"dcpath"; L"dcPath" ], Getopt.String ("path", set_string_option_once "--dcpath" dcpath), s_"Override dcPath (for vCenter)"; [ L"debug-overlay"; L"debug-overlays" ], Getopt.Set debug_overlays, s_"Save overlay files"; - [ S 'i' ], Getopt.String (i_options, set_input_mode), s_"Set input mode (default: libvirt)"; + [ S 'i' ], Getopt.Symbol (i_options, Modules_list.input_modules (), set_input_mode), s_"Set input mode (default: libvirt)"; [ M"ic" ], Getopt.String ("uri", set_string_option_once "-ic" input_conn), s_"Libvirt URI"; [ M"if" ], Getopt.String ("format", set_string_option_once "-if" input_format), @@ -182,8 +181,8 @@ let parse_cmdline () [ L"no-copy" ], Getopt.Clear do_copy, s_"Just write the metadata"; [ L"no-trim" ], Getopt.String ("-", no_trim_warning), s_"Ignored for backwards compatibility"; - [ S 'o' ], Getopt.String (o_options, set_output_mode), s_"Set output mode (default: libvirt)"; - [ M"oa" ], Getopt.String ("sparse|preallocated", set_output_alloc), + [ S 'o' ], Getopt.Symbol (o_options, Modules_list.output_modules (), set_output_mode), s_"Set output mode (default: libvirt)"; + [ M"oa" ], Getopt.Symbol (s_"mode", [ "sparse"; "preallocated" ], set_output_alloc), s_"Set output allocation mode"; [ M"oc" ], Getopt.String ("uri", set_string_option_once "-oc" output_conn), s_"Libvirt URI"; -- 2.7.4
Richard W.M. Jones
2016-Jul-18 17:35 UTC
Re: [Libguestfs] [PATCH 1/2] v2v: register also aliases of input/output modules
On Mon, Jul 18, 2016 at 07:29:53PM +0200, Pino Toscano wrote:> This makes them visible in the help text of -i and -o. > --- > v2v/input_disk.ml | 5 ++++- > v2v/output_local.ml | 5 ++++- > v2v/output_rhev.ml | 5 ++++- > 3 files changed, 12 insertions(+), 3 deletions(-) > > diff --git a/v2v/input_disk.ml b/v2v/input_disk.ml > index 17ad61d..508f16a 100644 > --- a/v2v/input_disk.ml > +++ b/v2v/input_disk.ml > @@ -101,4 +101,7 @@ class input_disk input_format disk = object > end > > let input_disk = new input_disk > -let () = Modules_list.register_input_module "disk" > +let () > + Modules_list.register_input_module "disk"; > + (* Alias *) > + Modules_list.register_input_module "local" > diff --git a/v2v/output_local.ml b/v2v/output_local.ml > index 47da929..f2945ec 100644 > --- a/v2v/output_local.ml > +++ b/v2v/output_local.ml > @@ -61,4 +61,7 @@ class output_local dir = object > end > > let output_local = new output_local > -let () = Modules_list.register_output_module "local" > +let () > + Modules_list.register_output_module "local"; > + (* Alias *) > + Modules_list.register_output_module "disk" > diff --git a/v2v/output_rhev.ml b/v2v/output_rhev.ml > index e45043b..bec5f44 100644 > --- a/v2v/output_rhev.ml > +++ b/v2v/output_rhev.ml > @@ -282,4 +282,7 @@ object > end > > let output_rhev = new output_rhev > -let () = Modules_list.register_output_module "rhev" > +let () > + Modules_list.register_output_module "rhev"; > + (* Alias *) > + Modules_list.register_output_module "ovirt"Technically this will alter the "Output to (-o)" combo box in virt-p2v so it lists both the options and their aliases. However I guess that isn't actually a problem. ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Richard W.M. Jones
2016-Jul-18 17:35 UTC
Re: [Libguestfs] [PATCH 2/2] v2v: use Getopt.Symbol for few options
On Mon, Jul 18, 2016 at 07:29:54PM +0200, Pino Toscano wrote:> Use Getopt.Symbol for options with a fixed list of choices, so there is > no need to check them on our own. > --- > v2v/cmdline.ml | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml > index 2d0a10a..ddf5858 100644 > --- a/v2v/cmdline.ml > +++ b/v2v/cmdline.ml > @@ -136,8 +136,7 @@ let parse_cmdline () > match mode with > | "sparse" -> output_alloc := `Sparse > | "preallocated" -> output_alloc := `Preallocated > - | s -> > - error (f_"unknown -oa option: %s") s > + | s -> assert false (* Already checked by Getopt.Symbol. *) > in > > let root_choice = ref AskRoot in > @@ -171,7 +170,7 @@ let parse_cmdline () > [ L"dcpath"; L"dcPath" ], Getopt.String ("path", set_string_option_once "--dcpath" dcpath), > s_"Override dcPath (for vCenter)"; > [ L"debug-overlay"; L"debug-overlays" ], Getopt.Set debug_overlays, s_"Save overlay files"; > - [ S 'i' ], Getopt.String (i_options, set_input_mode), s_"Set input mode (default: libvirt)"; > + [ S 'i' ], Getopt.Symbol (i_options, Modules_list.input_modules (), set_input_mode), s_"Set input mode (default: libvirt)"; > [ M"ic" ], Getopt.String ("uri", set_string_option_once "-ic" input_conn), > s_"Libvirt URI"; > [ M"if" ], Getopt.String ("format", set_string_option_once "-if" input_format), > @@ -182,8 +181,8 @@ let parse_cmdline () > [ L"no-copy" ], Getopt.Clear do_copy, s_"Just write the metadata"; > [ L"no-trim" ], Getopt.String ("-", no_trim_warning), > s_"Ignored for backwards compatibility"; > - [ S 'o' ], Getopt.String (o_options, set_output_mode), s_"Set output mode (default: libvirt)"; > - [ M"oa" ], Getopt.String ("sparse|preallocated", set_output_alloc), > + [ S 'o' ], Getopt.Symbol (o_options, Modules_list.output_modules (), set_output_mode), s_"Set output mode (default: libvirt)"; > + [ M"oa" ], Getopt.Symbol (s_"mode", [ "sparse"; "preallocated" ], set_output_alloc), > s_"Set output allocation mode"; > [ M"oc" ], Getopt.String ("uri", set_string_option_once "-oc" output_conn), > s_"Libvirt URI";ACK. 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
Reasonably Related Threads
- [PATCH v2 1/2] v2v: register also aliases of input/output modules
- [PATCH] v2v: use open_guestfs everywhere
- [PATCH 3/4] ocaml tools: Use global variables to store trace (-x) and verbose (-v) flags.
- v2v: Remove --no-trim, --vmtype options and other fixes.
- Re: [PATCH] v2v: use open_guestfs everywhere