2020-06-09 20:48:13 +00:00
|
|
|
From 692a752cf3e552790ada8cc07f937036adaa8bf0 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Pino Toscano <ptoscano@redhat.com>
|
|
|
|
Date: Thu, 21 Mar 2019 17:16:37 +0100
|
|
|
|
Subject: [PATCH] common/mltools: move the code for machine readable up
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
(cherry picked from commit 8b06ea0ebc9534e4fda9cc9a33c98f939401af79)
|
|
|
|
---
|
|
|
|
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;
|
|
|
|
--
|
2020-07-10 01:13:00 +00:00
|
|
|
2.25.4
|
2020-06-09 20:48:13 +00:00
|
|
|
|