From e0da108094c751a6d624372395908ead2287d6c5 Mon Sep 17 00:00:00 2001
From: lusitania <lusitania@users.noreply.github.com>
Date: Wed, 16 Sep 2015 17:43:00 +0200
Subject: [PATCH] Make colours, escape sequences optional

Coloured output is tedious to parse, even unnecessary where the report
backend is not a terminal.

Signed-off-by: lusitania <lusitania@users.noreply.github.com>
---
 README.md                |  6 ++++++
 docker-bench-security.sh |  1 +
 output_lib.sh            | 22 +++++++++++++++++-----
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index 56bfe5a..1505105 100644
--- a/README.md
+++ b/README.md
@@ -51,4 +51,10 @@ cd docker-bench-security
 sh docker-bench-security.sh
 ```
 
+Coloured output may be switched off to ease parsing:
+
+```sh
+sh docker-bench-security.sh -n |& grep '^\[WARN\]'
+```
+
 This script was build to be POSIX 2004 compliant, so it should be portable across any Unix platform.
diff --git a/docker-bench-security.sh b/docker-bench-security.sh
index 0659d07..ae67d67 100755
--- a/docker-bench-security.sh
+++ b/docker-bench-security.sh
@@ -37,6 +37,7 @@ usage () {
   cat <<EOF
   usage: ${myname} [options]
 
+  -n           optional  Don't colourise results
   -h           optional  Print this help message
   -l PATH      optional  Log output in PATH
 EOF
diff --git a/output_lib.sh b/output_lib.sh
index f4f61bc..0b9558b 100644
--- a/output_lib.sh
+++ b/output_lib.sh
@@ -1,9 +1,21 @@
 #!/bin/sh
-bldred='\033[1;31m'
-bldgrn='\033[1;32m'
-bldblu='\033[1;34m'
-bldylw='\033[1;33m' # Yellow
-txtrst='\033[0m'
+getopts n opts
+case "$opts" in
+    n)
+        bldred=
+        bldgrn=
+        bldblu=
+        bldylw=
+        txtrst=
+        ;;
+    *)
+        bldred='\033[1;31m'
+        bldgrn='\033[1;32m'
+        bldblu='\033[1;34m'
+        bldylw='\033[1;33m' # Yellow
+        txtrst='\033[0m'
+        ;;
+esac
 
 logit () {
   printf "%b\n" "$1" | tee -a "$logger"