[Libguestfs] [PATCH v2 4/5] tools: Add machine_output function.

Richard W.M. Jones rjones at redhat.com
Fri Mar 16 13:30:42 UTC 2018


Produces machine-readable output delimited by special markers
__MACHINEBEGIN__
__MACHINEEND__
---
 common/mltools/tools_utils.ml  |  8 ++++++++
 common/mltools/tools_utils.mli | 11 +++++++++++
 2 files changed, 19 insertions(+)

diff --git a/common/mltools/tools_utils.ml b/common/mltools/tools_utils.ml
index 09f1bb544..f7abd5c3e 100644
--- a/common/mltools/tools_utils.ml
+++ b/common/mltools/tools_utils.ml
@@ -102,6 +102,14 @@ let debug fs =
   let display str = if verbose () then prerr_endline str in
   ksprintf display fs
 
+let machine_output fs =
+  let display str =
+    print_endline "__MACHINEBEGIN__";
+    print_endline str;
+    print_endline "__MACHINEEND__"
+  in
+  ksprintf display fs
+
 (* Common function to create a new Guestfs handle, with common options
  * (e.g. debug, tracing) already set.
  *)
diff --git a/common/mltools/tools_utils.mli b/common/mltools/tools_utils.mli
index dac6b4120..d40e0aa9b 100644
--- a/common/mltools/tools_utils.mli
+++ b/common/mltools/tools_utils.mli
@@ -36,6 +36,17 @@ val debug : ('a, unit, string, unit) format4 -> 'a
     the command line.  As with libguestfs debugging messages, it is
     sent to [stderr]. *)
 
+val machine_output : ('a, unit, string, unit) format4 -> 'a
+(** Output meant to be parsed by another program.
+
+    It is printed with no wrapping or other interpretation as:
+    {v
+    __MACHINEBEGIN__
+    <<output, possibly multiple lines>>
+    __MACHINEEND__
+    v}
+ *)
+
 val open_guestfs : ?identifier:string -> unit -> Guestfs.guestfs
 (** Common function to create a new Guestfs handle, with common options
     (e.g. debug, tracing) already set.
-- 
2.13.2




More information about the Libguestfs mailing list