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