On Thursday, 22 March 2018 16:24:23 CET Richard W.M. Jones wrote:
+ (* Input transport affects whether some input options should or + * should not be used. + *) + let input_transport = + let is_query = input_options = ["?", ""] in + let no_options () = + if is_query then ( + printf (f_"No -io (input options) are supported with this input transport.\n"); + exit 0 + ) + else if input_options <> [] then + error (f_"no -io (input options) are allowed here"); + in + match input_transport with + | None -> no_options (); None + | Some `SSH -> no_options (); Some `SSH + | Some `VDDK -> + if is_query then ( + Input_libvirt_vddk.print_vddk_input_options (); + exit 0 + ) + else ( + let vddk_options = + Input_libvirt_vddk.parse_vddk_input_options input_options in + Some (`VDDK vddk_options) + ) in + + (* Output mode affects whether some output options should or + * should not be used. + *) + let output_mode = + let is_query = output_options = ["?", ""] in + let no_options () = + if is_query then ( + printf (f_"No -oo (output options) are supported in this output mode.\n"); + exit 0 + ) + else if output_options <> [] then + error (f_"no -oo (output options) are allowed here"); + in + match output_mode with + | `Not_set -> no_options (); `Not_set + | `Glance -> no_options (); `Glance + | `Libvirt -> no_options (); `Libvirt + | `Local -> no_options (); `Local + | `Null -> no_options (); `Null + | `RHV -> no_options (); `RHV + | `QEmu -> no_options (); `QEmu + | `VDSM -> + if is_query then ( + Output_vdsm.print_vdsm_output_options (); + exit 0 + ) + else ( + let vdsm_options = + Output_vdsm.parse_vdsm_output_options output_options in + `VDSM vdsm_options + ) in
Here I'd do the check of the options (both input and output) by prefixes, i.e. things like: List.iter ( fun key -> if not (String.is_prefix key "vddk-") || not (List.mem key vddk_option_keys) then error (f_"-it vddk: ‘-io %s’ is not a valid input option") key ) keys; So most probably adding a simple function to get the prefix of options per-input and per-output mode, and using it to check. The rest LGTM. -- Pino Toscano