mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
mltools: create a cmdline_options struct
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 ());
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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:";
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user