Blame SOURCES/0111-virt-tools-Add-common-colours-option.patch

e76f14
From 3b7c70dea311561c4ffe69ceee65a994a5543862 Mon Sep 17 00:00:00 2001
e76f14
From: "Richard W.M. Jones" <rjones@redhat.com>
e76f14
Date: Sat, 18 Jun 2016 10:22:46 +0100
e76f14
Subject: [PATCH] virt tools: Add common --colours option.
e76f14
e76f14
This option (alternately spelled: --color, --colour, --colors, or
e76f14
--colours) enables ANSI colour sequences output even if that would be
e76f14
disabled becaues the output is not a TTY.
e76f14
e76f14
(cherry picked from commit b000d6bc68543035e3fc14853c8a9f518ed1b0f3)
e76f14
---
e76f14
 builder/virt-builder.pod       |  9 +++++++++
e76f14
 customize/virt-customize.pod   |  9 +++++++++
e76f14
 dib/virt-dib.pod               |  9 +++++++++
e76f14
 get-kernel/virt-get-kernel.pod |  9 +++++++++
e76f14
 mllib/common_utils.ml          | 42 +++++++++++++++++++++++++-----------------
e76f14
 resize/virt-resize.pod         |  9 +++++++++
e76f14
 sparsify/virt-sparsify.pod     |  9 +++++++++
e76f14
 sysprep/virt-sysprep.pod       |  9 +++++++++
e76f14
 v2v/cmdline.ml                 |  1 +
e76f14
 v2v/virt-v2v.pod               |  9 +++++++++
e76f14
 10 files changed, 98 insertions(+), 17 deletions(-)
e76f14
e76f14
diff --git a/builder/virt-builder.pod b/builder/virt-builder.pod
e76f14
index 94ba430..5e344de 100644
e76f14
--- a/builder/virt-builder.pod
e76f14
+++ b/builder/virt-builder.pod
e76f14
@@ -241,6 +241,15 @@ Using I<--no-check-signature> bypasses this check.
e76f14
 
e76f14
 See also I<--fingerprint>.
e76f14
 
e76f14
+=item B<--colors>
e76f14
+
e76f14
+=item B<--colours>
e76f14
+
e76f14
+Use ANSI colour sequences to colourize messages.  This is the default
e76f14
+when the output is a tty.  If the output of the program is redirected
e76f14
+to a file, ANSI colour sequences are disabled unless you use this
e76f14
+option.
e76f14
+
e76f14
 =item B<--curl> CURL
e76f14
 
e76f14
 Specify an alternate L<curl(1)> binary.  You can also use this to add
e76f14
diff --git a/customize/virt-customize.pod b/customize/virt-customize.pod
e76f14
index 8fb9931..e8eb148 100644
e76f14
--- a/customize/virt-customize.pod
e76f14
+++ b/customize/virt-customize.pod
e76f14
@@ -74,6 +74,15 @@ disk format (not just an ISO).
e76f14
 Specify the disk format for the next I<--attach> option.  The
e76f14
 C<FORMAT> is usually C<raw> or C<qcow2>.  Use C<raw> for ISOs.
e76f14
 
e76f14
+=item B<--colors>
e76f14
+
e76f14
+=item B<--colours>
e76f14
+
e76f14
+Use ANSI colour sequences to colourize messages.  This is the default
e76f14
+when the output is a tty.  If the output of the program is redirected
e76f14
+to a file, ANSI colour sequences are disabled unless you use this
e76f14
+option.
e76f14
+
e76f14
 =item B<-c> URI
e76f14
 
e76f14
 =item B<--connect> URI
e76f14
diff --git a/dib/virt-dib.pod b/dib/virt-dib.pod
e76f14
index 9baae23..8ccb9f5 100644
e76f14
--- a/dib/virt-dib.pod
e76f14
+++ b/dib/virt-dib.pod
e76f14
@@ -72,6 +72,15 @@ Right now this option does nothing more than setting the C<ARCH>
e76f14
 environment variable for the elements, and it's up to them to
e76f14
 produce an image for the requested architecture.
e76f14
 
e76f14
+=item B<--colors>
e76f14
+
e76f14
+=item B<--colours>
e76f14
+
e76f14
+Use ANSI colour sequences to colourize messages.  This is the default
e76f14
+when the output is a tty.  If the output of the program is redirected
e76f14
+to a file, ANSI colour sequences are disabled unless you use this
e76f14
+option.
e76f14
+
e76f14
 =item B<--debug> LEVEL
e76f14
 
e76f14
 Set the debug level to C<LEVEL>, which is a non-negative integer
e76f14
diff --git a/get-kernel/virt-get-kernel.pod b/get-kernel/virt-get-kernel.pod
e76f14
index 92d6cb6..97a159c 100644
e76f14
--- a/get-kernel/virt-get-kernel.pod
e76f14
+++ b/get-kernel/virt-get-kernel.pod
e76f14
@@ -44,6 +44,15 @@ force a particular format use the I<--format> option.
e76f14
 Add a remote disk.  The URI format is compatible with guestfish.
e76f14
 See L<guestfish(1)/ADDING REMOTE STORAGE>.
e76f14
 
e76f14
+=item B<--colors>
e76f14
+
e76f14
+=item B<--colours>
e76f14
+
e76f14
+Use ANSI colour sequences to colourize messages.  This is the default
e76f14
+when the output is a tty.  If the output of the program is redirected
e76f14
+to a file, ANSI colour sequences are disabled unless you use this
e76f14
+option.
e76f14
+
e76f14
 =item B<-c> URI
e76f14
 
e76f14
 =item B<--connect> URI
e76f14
diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
e76f14
index be8810a..7bd02f8 100644
e76f14
--- a/mllib/common_utils.ml
e76f14
+++ b/mllib/common_utils.ml
e76f14
@@ -299,27 +299,16 @@ let protect ~f ~finally =
e76f14
   finally ();
e76f14
   match r with Either ret -> ret | Or exn -> raise exn
e76f14
 
e76f14
-let istty chan =
e76f14
-  Unix.isatty (Unix.descr_of_out_channel chan)
e76f14
-
e76f14
-(* ANSI terminal colours. *)
e76f14
-let ansi_green ?(chan = stdout) () =
e76f14
-  if istty chan then output_string chan "\x1b[0;32m"
e76f14
-let ansi_red ?(chan = stdout) () =
e76f14
-  if istty chan then output_string chan "\x1b[1;31m"
e76f14
-let ansi_blue ?(chan = stdout) () =
e76f14
-  if istty chan then output_string chan "\x1b[1;34m"
e76f14
-let ansi_magenta ?(chan = stdout) () =
e76f14
-  if istty chan then output_string chan "\x1b[1;35m"
e76f14
-let ansi_restore ?(chan = stdout) () =
e76f14
-  if istty chan then output_string chan "\x1b[0m"
e76f14
-
e76f14
 (* Program name. *)
e76f14
 let prog = Filename.basename Sys.executable_name
e76f14
 
e76f14
-(* Stores the quiet (--quiet), trace (-x) and verbose (-v) flags in a
e76f14
- * global variable.
e76f14
+(* Stores the colours (--colours), quiet (--quiet), trace (-x) and
e76f14
+ * verbose (-v) flags in a global variable.
e76f14
  *)
e76f14
+let colours = ref false
e76f14
+let set_colours () = colours := true
e76f14
+let colours () = !colours
e76f14
+
e76f14
 let quiet = ref false
e76f14
 let set_quiet () = quiet := true
e76f14
 let quiet () = !quiet
e76f14
@@ -332,6 +321,21 @@ let verbose = ref false
e76f14
 let set_verbose () = verbose := true
e76f14
 let verbose () = !verbose
e76f14
 
e76f14
+(* ANSI terminal colours. *)
e76f14
+let istty chan =
e76f14
+  Unix.isatty (Unix.descr_of_out_channel chan)
e76f14
+
e76f14
+let ansi_green ?(chan = stdout) () =
e76f14
+  if colours () || istty chan then output_string chan "\x1b[0;32m"
e76f14
+let ansi_red ?(chan = stdout) () =
e76f14
+  if colours () || istty chan then output_string chan "\x1b[1;31m"
e76f14
+let ansi_blue ?(chan = stdout) () =
e76f14
+  if colours () || istty chan then output_string chan "\x1b[1;34m"
e76f14
+let ansi_magenta ?(chan = stdout) () =
e76f14
+  if colours () || istty chan then output_string chan "\x1b[1;35m"
e76f14
+let ansi_restore ?(chan = stdout) () =
e76f14
+  if colours () || istty chan then output_string chan "\x1b[0m"
e76f14
+
e76f14
 (* Timestamped progress messages, used for ordinary messages when not
e76f14
  * --quiet.
e76f14
  *)
e76f14
@@ -596,6 +600,10 @@ let set_standard_options argspec =
e76f14
     "--debug-gc",   Arg.Unit set_debug_gc,     " " ^ s_"Debug GC and memory allocations (internal)";
e76f14
     "-q",           Arg.Unit set_quiet,        " " ^ s_"Don't print progress messages";
e76f14
     "--quiet",      Arg.Unit set_quiet,        " " ^ s_"Don't print progress messages";
e76f14
+    "--color",      Arg.Unit set_colours,      " " ^ s_"Use ANSI colour sequences even if not tty";
e76f14
+    "--colors",     Arg.Unit set_colours,      " " ^ s_"Use ANSI colour sequences even if not tty";
e76f14
+    "--colour",     Arg.Unit set_colours,      " " ^ s_"Use ANSI colour sequences even if not tty";
e76f14
+    "--colours",    Arg.Unit set_colours,      " " ^ s_"Use ANSI colour sequences even if not tty";
e76f14
   ] @ argspec in
e76f14
   let argspec =
e76f14
     let cmp (arg1, _, _) (arg2, _, _) = compare_command_line_args arg1 arg2 in
e76f14
diff --git a/resize/virt-resize.pod b/resize/virt-resize.pod
e76f14
index a0ab459..2b2a485 100644
e76f14
--- a/resize/virt-resize.pod
e76f14
+++ b/resize/virt-resize.pod
e76f14
@@ -327,6 +327,15 @@ since around 2008.
e76f14
 
e76f14
 =back
e76f14
 
e76f14
+=item B<--colors>
e76f14
+
e76f14
+=item B<--colours>
e76f14
+
e76f14
+Use ANSI colour sequences to colourize messages.  This is the default
e76f14
+when the output is a tty.  If the output of the program is redirected
e76f14
+to a file, ANSI colour sequences are disabled unless you use this
e76f14
+option.
e76f14
+
e76f14
 =item B<-d>
e76f14
 
e76f14
 =item B<--debug>
e76f14
diff --git a/sparsify/virt-sparsify.pod b/sparsify/virt-sparsify.pod
e76f14
index b841251..44f7d4e 100644
e76f14
--- a/sparsify/virt-sparsify.pod
e76f14
+++ b/sparsify/virt-sparsify.pod
e76f14
@@ -155,6 +155,15 @@ B<fail> and exit.
e76f14
 
e76f14
 You cannot use this option and I<--in-place> together.
e76f14
 
e76f14
+=item B<--colors>
e76f14
+
e76f14
+=item B<--colours>
e76f14
+
e76f14
+Use ANSI colour sequences to colourize messages.  This is the default
e76f14
+when the output is a tty.  If the output of the program is redirected
e76f14
+to a file, ANSI colour sequences are disabled unless you use this
e76f14
+option.
e76f14
+
e76f14
 =item B<--compress>
e76f14
 
e76f14
 Compress the output file.  This I<only> works if the output format is
e76f14
diff --git a/sysprep/virt-sysprep.pod b/sysprep/virt-sysprep.pod
e76f14
index 44cf7f8..d671443 100644
e76f14
--- a/sysprep/virt-sysprep.pod
e76f14
+++ b/sysprep/virt-sysprep.pod
e76f14
@@ -59,6 +59,15 @@ force a particular format use the I<--format> option.
e76f14
 Add a remote disk.  The URI format is compatible with guestfish.
e76f14
 See L<guestfish(1)/ADDING REMOTE STORAGE>.
e76f14
 
e76f14
+=item B<--colors>
e76f14
+
e76f14
+=item B<--colours>
e76f14
+
e76f14
+Use ANSI colour sequences to colourize messages.  This is the default
e76f14
+when the output is a tty.  If the output of the program is redirected
e76f14
+to a file, ANSI colour sequences are disabled unless you use this
e76f14
+option.
e76f14
+
e76f14
 =item B<-c> URI
e76f14
 
e76f14
 =item B<--connect> URI
e76f14
diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml
e76f14
index 4623af9..b9992eb 100644
e76f14
--- a/v2v/cmdline.ml
e76f14
+++ b/v2v/cmdline.ml
e76f14
@@ -296,6 +296,7 @@ read the man page virt-v2v(1).
e76f14
   if args = [] && machine_readable then (
e76f14
     printf "virt-v2v\n";
e76f14
     printf "libguestfs-rewrite\n";
e76f14
+    printf "colours-option\n";
e76f14
     List.iter (printf "input:%s\n") (Modules_list.input_modules ());
e76f14
     List.iter (printf "output:%s\n") (Modules_list.output_modules ());
e76f14
     List.iter (printf "convert:%s\n") (Modules_list.convert_modules ());
e76f14
diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod
e76f14
index 5800b34..93f0e77 100644
e76f14
--- a/v2v/virt-v2v.pod
e76f14
+++ b/v2v/virt-v2v.pod
e76f14
@@ -154,6 +154,15 @@ Display help.
e76f14
 
e76f14
 See I<--network> below.
e76f14
 
e76f14
+=item B<--colors>
e76f14
+
e76f14
+=item B<--colours>
e76f14
+
e76f14
+Use ANSI colour sequences to colourize messages.  This is the default
e76f14
+when the output is a tty.  If the output of the program is redirected
e76f14
+to a file, ANSI colour sequences are disabled unless you use this
e76f14
+option.
e76f14
+
e76f14
 =item B<--compressed>
e76f14
 
e76f14
 Write a compressed output file.  This is only allowed if the output
e76f14
-- 
aa0300
2.7.4
e76f14