[Libguestfs] [PATCH v2 1/4] common/mltools: move the code for machine readable up

Richard W.M. Jones rjones at redhat.com
Fri Mar 29 12:49:08 UTC 2019


On Thu, Mar 28, 2019 at 05:59:28PM +0100, Pino Toscano wrote:
> Move the code for handling machine readable up in the file, so it can be
> used by other functions.
> 
> Only code motion, no behaviour changes.

ACKed before, ACKed again.

Rich.

>  common/mltools/tools_utils.ml | 60 +++++++++++++++++------------------
>  1 file changed, 30 insertions(+), 30 deletions(-)
> 
> diff --git a/common/mltools/tools_utils.ml b/common/mltools/tools_utils.ml
> index 24641369e..5a35708cd 100644
> --- a/common/mltools/tools_utils.ml
> +++ b/common/mltools/tools_utils.ml
> @@ -33,6 +33,36 @@ external c_inspect_decrypt : Guestfs.t -> int64 -> (string * key_store_key) list
>  external c_set_echo_keys : unit -> unit = "guestfs_int_mllib_set_echo_keys" "noalloc"
>  external c_set_keys_from_stdin : unit -> unit = "guestfs_int_mllib_set_keys_from_stdin" "noalloc"
>  
> +type machine_readable_fn = {
> +  pr : 'a. ('a, unit, string, unit) format4 -> 'a;
> +} (* [@@unboxed] *)
> +
> +type machine_readable_output_type =
> +  | NoOutput
> +  | Channel of out_channel
> +  | File of string
> +let machine_readable_output = ref NoOutput
> +let machine_readable_channel = ref None
> +let machine_readable () =
> +  let chan =
> +    if !machine_readable_channel = None then (
> +      let chan =
> +        match !machine_readable_output with
> +        | NoOutput -> None
> +        | Channel chan -> Some chan
> +        | File f -> Some (open_out f) in
> +      machine_readable_channel := chan
> +    );
> +    !machine_readable_channel
> +  in
> +  match chan with
> +  | None -> None
> +  | Some chan ->
> +    let pr fs =
> +      ksprintf (output_string chan) fs
> +    in
> +    Some { pr }
> +
>  (* ANSI terminal colours. *)
>  let istty chan =
>    Unix.isatty (Unix.descr_of_out_channel chan)
> @@ -236,36 +266,6 @@ let human_size i =
>      )
>    )
>  
> -type machine_readable_fn = {
> -  pr : 'a. ('a, unit, string, unit) format4 -> 'a;
> -} (* [@@unboxed] *)
> -
> -type machine_readable_output_type =
> -  | NoOutput
> -  | Channel of out_channel
> -  | File of string
> -let machine_readable_output = ref NoOutput
> -let machine_readable_channel = ref None
> -let machine_readable () =
> -  let chan =
> -    if !machine_readable_channel = None then (
> -      let chan =
> -        match !machine_readable_output with
> -        | NoOutput -> None
> -        | Channel chan -> Some chan
> -        | File f -> Some (open_out f) in
> -      machine_readable_channel := chan
> -    );
> -    !machine_readable_channel
> -  in
> -  match chan with
> -  | None -> None
> -  | Some chan ->
> -    let pr fs =
> -      ksprintf (output_string chan) fs
> -    in
> -    Some { pr }
> -
>  type cmdline_options = {
>    getopt : Getopt.t;
>    ks : key_store;
> -- 
> 2.20.1
> 
> _______________________________________________
> Libguestfs mailing list
> Libguestfs at redhat.com
> https://www.redhat.com/mailman/listinfo/libguestfs

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org




More information about the Libguestfs mailing list