Instead of returning directly a Getopt.t handle, now
Tools_utils.create_standard_options returns a struct, which at the
moment contains only the Getopt.t handle. This way, it will be easy to
add more data needed for handling standard command line options.
This is mostly refactoring, with no functional changes.
---
builder/cmdline.ml | 2 +-
builder/repository_main.ml | 2 +-
common/mltools/getopt_tests.ml | 2 +-
common/mltools/machine_readable_tests.ml | 2 +-
common/mltools/tools_utils.ml | 9 ++++++++-
common/mltools/tools_utils.mli | 10 ++++++++--
customize/customize_main.ml | 2 +-
dib/cmdline.ml | 2 +-
get-kernel/get_kernel.ml | 2 +-
resize/resize.ml | 2 +-
sparsify/cmdline.ml | 2 +-
sysprep/main.ml | 2 +-
v2v/cmdline.ml | 2 +-
v2v/copy_to_local.ml | 2 +-
14 files changed, 28 insertions(+), 15 deletions(-)
diff --git a/builder/cmdline.ml b/builder/cmdline.ml
index f05aecc76..bd099e218 100644
--- a/builder/cmdline.ml
+++ b/builder/cmdline.ml
@@ -191,7 +191,7 @@ read the man page virt-builder(1).
")
prog in
let opthandle = create_standard_options argspec ~anon_fun ~machine_readable:true
usage_msg in
- Getopt.parse opthandle;
+ Getopt.parse opthandle.getopt;
(* Dereference options. *)
let args = List.rev !args in
diff --git a/builder/repository_main.ml b/builder/repository_main.ml
index 554715a73..60ee96299 100644
--- a/builder/repository_main.ml
+++ b/builder/repository_main.ml
@@ -69,7 +69,7 @@ read the man page virt-builder-repository(1).
")
prog in
let opthandle = create_standard_options argspec ~anon_fun ~machine_readable:true
usage_msg in
- Getopt.parse opthandle;
+ Getopt.parse opthandle.getopt;
(* Machine-readable mode? Print out some facts about what
* this binary supports.
diff --git a/common/mltools/getopt_tests.ml b/common/mltools/getopt_tests.ml
index 1617b3056..ca6ce5d48 100644
--- a/common/mltools/getopt_tests.ml
+++ b/common/mltools/getopt_tests.ml
@@ -68,7 +68,7 @@ let print_optstring_value = function
let opthandle = create_standard_options argspec ~anon_fun usage_msg
let () =
- Getopt.parse opthandle;
+ Getopt.parse opthandle.getopt;
(* Implicit settings. *)
printf "trace = %b\n" (trace ());
diff --git a/common/mltools/machine_readable_tests.ml
b/common/mltools/machine_readable_tests.ml
index 907f05207..809eff01d 100644
--- a/common/mltools/machine_readable_tests.ml
+++ b/common/mltools/machine_readable_tests.ml
@@ -30,7 +30,7 @@ let usage_msg = sprintf "%s: test the --machine-readable
functionality" prog
let opthandle = create_standard_options [] ~machine_readable:true usage_msg
let () =
- Getopt.parse opthandle;
+ Getopt.parse opthandle.getopt;
print_endline "on-stdout";
prerr_endline "on-stderr";
diff --git a/common/mltools/tools_utils.ml b/common/mltools/tools_utils.ml
index c4f230275..2b2d43db9 100644
--- a/common/mltools/tools_utils.ml
+++ b/common/mltools/tools_utils.ml
@@ -259,6 +259,10 @@ let machine_readable () =
in
Some { pr }
+type cmdline_options = {
+ getopt : Getopt.t;
+}
+
let create_standard_options argspec ?anon_fun ?(key_opts = false) ?(machine_readable =
false) usage_msg =
(** Install an exit hook to check gc consistency for --debug-gc *)
let set_debug_gc () =
@@ -306,7 +310,10 @@ let create_standard_options argspec ?anon_fun ?(key_opts = false)
?(machine_read
[ L"machine-readable" ], Getopt.OptString ("format",
parse_machine_readable), s_"Make output machine readable";
]
else []) in
- Getopt.create argspec ?anon_fun usage_msg
+ let getopt = Getopt.create argspec ?anon_fun usage_msg in
+ {
+ getopt;
+ }
(* Run an external command, slurp up the output as a list of lines. *)
let external_command ?(echo_cmd = true) cmd =
diff --git a/common/mltools/tools_utils.mli b/common/mltools/tools_utils.mli
index 2b8c2b78a..99984bfa1 100644
--- a/common/mltools/tools_utils.mli
+++ b/common/mltools/tools_utils.mli
@@ -74,7 +74,13 @@ val machine_readable : unit -> machine_readable_fn option
readable output to, in case it was enabled via
[--machine-readable]. *)
-val create_standard_options : Getopt.speclist -> ?anon_fun:Getopt.anon_fun ->
?key_opts:bool -> ?machine_readable:bool -> Getopt.usage_msg -> Getopt.t
+type cmdline_options = {
+ getopt : Getopt.t; (** The actual Getopt handle. *)
+}
+(** Structure representing all the data needed for handling command
+ line options. *)
+
+val create_standard_options : Getopt.speclist -> ?anon_fun:Getopt.anon_fun ->
?key_opts:bool -> ?machine_readable:bool -> Getopt.usage_msg -> cmdline_options
(** Adds the standard libguestfs command line options to the specified ones,
sorting them, and setting [long_options] to them.
@@ -84,7 +90,7 @@ val create_standard_options : Getopt.speclist ->
?anon_fun:Getopt.anon_fun -> ?k
[machine_readable] specifies whether add the [--machine-readable]
option.
- Returns a new [Getopt.t] handle. *)
+ Returns a new [cmdline_options] structure. *)
val external_command : ?echo_cmd:bool -> string -> string list
(** Run an external command, slurp up the output as a list of lines.
diff --git a/customize/customize_main.ml b/customize/customize_main.ml
index 8ba4f5ce7..b4da87368 100644
--- a/customize/customize_main.ml
+++ b/customize/customize_main.ml
@@ -103,7 +103,7 @@ read the man page virt-customize(1).
")
prog in
let opthandle = create_standard_options argspec ~key_opts:true usage_msg in
- Getopt.parse opthandle;
+ Getopt.parse opthandle.getopt;
if not !format_consumed then
error (f_"--format parameter must appear before -a parameter");
diff --git a/dib/cmdline.ml b/dib/cmdline.ml
index 5f0cb6dca..220350d9d 100644
--- a/dib/cmdline.ml
+++ b/dib/cmdline.ml
@@ -196,7 +196,7 @@ read the man page virt-dib(1).
let argspec = argspec @ Output_format.extra_args () in
let opthandle = create_standard_options argspec ~anon_fun:append_element
~machine_readable:true usage_msg in
- Getopt.parse opthandle;
+ Getopt.parse opthandle.getopt;
let debug = !debug in
let basepath = !basepath in
diff --git a/get-kernel/get_kernel.ml b/get-kernel/get_kernel.ml
index c11136adb..cbc617bb8 100644
--- a/get-kernel/get_kernel.ml
+++ b/get-kernel/get_kernel.ml
@@ -70,7 +70,7 @@ read the man page virt-get-kernel(1).
")
prog in
let opthandle = create_standard_options argspec ~key_opts:true ~machine_readable:true
usage_msg in
- Getopt.parse opthandle;
+ Getopt.parse opthandle.getopt;
(* Machine-readable mode? Print out some facts about what
* this binary supports.
diff --git a/resize/resize.ml b/resize/resize.ml
index fe1389b6e..63f911d2c 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -224,7 +224,7 @@ read the man page virt-resize(1).
")
prog in
let opthandle = create_standard_options argspec ~anon_fun ~machine_readable:true
usage_msg in
- Getopt.parse opthandle;
+ Getopt.parse opthandle.getopt;
if verbose () then (
printf "command line:";
diff --git a/sparsify/cmdline.ml b/sparsify/cmdline.ml
index 4ef43a505..ca509b97f 100644
--- a/sparsify/cmdline.ml
+++ b/sparsify/cmdline.ml
@@ -89,7 +89,7 @@ read the man page virt-sparsify(1).
")
prog in
let opthandle = create_standard_options argspec ~anon_fun ~key_opts:true
~machine_readable:true usage_msg in
- Getopt.parse opthandle;
+ Getopt.parse opthandle.getopt;
(* Dereference the rest of the args. *)
let check_tmpdir = !check_tmpdir in
diff --git a/sysprep/main.ml b/sysprep/main.ml
index 980b62a35..37fe6be01 100644
--- a/sysprep/main.ml
+++ b/sysprep/main.ml
@@ -149,7 +149,7 @@ read the man page virt-sysprep(1).
")
prog in
let opthandle = create_standard_options args ~key_opts:true usage_msg in
- Getopt.parse opthandle;
+ Getopt.parse opthandle.getopt;
if not !format_consumed then
error (f_"--format parameter must appear before -a parameter");
diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml
index f051738b2..29c3e5d4f 100644
--- a/v2v/cmdline.ml
+++ b/v2v/cmdline.ml
@@ -300,7 +300,7 @@ read the man page virt-v2v(1).
")
prog in
let opthandle = create_standard_options argspec ~anon_fun ~key_opts:true
~machine_readable:true usage_msg in
- Getopt.parse opthandle;
+ Getopt.parse opthandle.getopt;
(* Dereference the arguments. *)
let args = List.rev !args in
diff --git a/v2v/copy_to_local.ml b/v2v/copy_to_local.ml
index c626b6368..86ff72b3a 100644
--- a/v2v/copy_to_local.ml
+++ b/v2v/copy_to_local.ml
@@ -76,7 +76,7 @@ read the man page virt-v2v-copy-to-local(1).
")
prog in
let opthandle = create_standard_options argspec ~anon_fun usage_msg in
- Getopt.parse opthandle;
+ Getopt.parse opthandle.getopt;
let args = !args in
let input_conn = !input_conn in
--
2.17.1