From 0a94a9085ad97e23895eded411c1c7d94e8ddf18 Mon Sep 17 00:00:00 2001
From: Giovanni Bussi <giovanni.bussi@gmail.com>
Date: Mon, 9 Dec 2013 17:43:59 +0100
Subject: [PATCH] Added -q option to patch

Allows to avoid verbose logging. The option is now used in user-doc/extract
to simplify the generation of code-specific notes

(cherry picked from commit 7152d46f43f7322dc9a365fceaf8c455ea85564c)

Conflicts:
	patches/patch.sh
---
 patches/patch.sh | 55 ++++++++++++++++++++++++++++++------------------
 user-doc/extract |  2 +-
 2 files changed, 35 insertions(+), 22 deletions(-)

diff --git a/patches/patch.sh b/patches/patch.sh
index 60437c10b..dbd66ef03 100755
--- a/patches/patch.sh
+++ b/patches/patch.sh
@@ -30,6 +30,9 @@ Options:
                     same as --mode runtime
   -d FILE, --diff FILE
                     set the path to diff file (default: ROOT/patches/ENGINE.diff) (*)
+  -q, --quiet
+                    do not write loggin information; useful with -i to print just
+                    the patching information
   -f, --force
                     force patching (*)
 
@@ -47,6 +50,10 @@ newpatch=
 
 multiple_actions=
 
+otherfiles=
+save_originals=
+quiet=
+
 for option
 do
 
@@ -74,6 +81,7 @@ do
     (--shared) mode=shared ;;
     (--runtime) mode=runtime ;;
     (--force|-f) force=yes ;;
+    (--quiet|-q) quiet=yes ;;
     (*)
       echo "ERROR: Unknown option $prefix_option. Use -h for help."
       exit
@@ -90,8 +98,8 @@ if [ -z "$action" ] ; then
   exit
 fi
 
-echo "PLUMED patching tool"
-echo
+test -n "$quiet" || echo "PLUMED patching tool"
+test -n "$quiet" || echo
 if [ -z "$PLUMED_ROOT" ]
 then
   echo "ERROR: I cannot find PLUMED"
@@ -129,14 +137,14 @@ fi
 
 if [ "$action" == new ]
 then
-  echo "Creating a new patch"
+  test -n "$quiet" || echo "Creating a new patch"
   if [[ -e "$PLUMED_ROOT"/patches/"$newpatch".diff ]] ; then
       echo "ERROR: patch $newpatch is already defined"
       exit
   fi
   touch "$PLUMED_ROOT"/patches/"$newpatch".diff
-  echo "Created file $PLUMED_ROOT/patches/$newpatch.diff"
-  echo "Also consider the possibility of adding a $PLUMED_ROOT/patches/$newpatch.config file"
+  test -n "$quiet" || echo "Created file $PLUMED_ROOT/patches/$newpatch.diff"
+  test -n "$quiet" || echo "Also consider the possibility of adding a $PLUMED_ROOT/patches/$newpatch.config file"
   exit
 fi
 
@@ -165,19 +173,19 @@ then
   test -d "$PLUMED_ROOT/patches/${engine}" && otherfiles="$PLUMED_ROOT/patches/${engine}/"
 fi
 
-echo "MD engine: $engine"
-echo "PLUMED location: $PLUMED_ROOT"
-echo "diff file: $diff"
+test -n "$quiet" || echo "MD engine: $engine"
+test -n "$quiet" || echo "PLUMED location: $PLUMED_ROOT"
+test -n "$quiet" || echo "diff file: $diff"
 
 if [ -f "$config" ]
 then
-  echo "sourcing config file: $config"
+  test -n "$quiet" || echo "sourcing config file: $config"
   source "$config"
 fi
 
 if [ -d "$otherfiles" ]
 then
-  echo "extra files located in: $otherfiles"
+  test -n "$quiet" || echo "extra files located in: $otherfiles"
 fi
 
 case "$mode" in
@@ -216,21 +224,26 @@ case "$action" in
       exit
     fi
     if type -t plumed_before_patch 1>/dev/null ; then
-      echo "Executing plumed_before_patch function"
+      test -n "$quiet" || echo "Executing plumed_before_patch function"
       plumed_before_patch
     fi
-    echo "Linking Plumed.h and Plumed.inc ($mode mode)"
+    test -n "$quiet" || echo "Linking Plumed.h and Plumed.inc ($mode mode)"
     ln -s "$PLUMED_ROOT/src/wrapper/Plumed.h"
     ln -s "$PLUMED_ROOT/src/lib/Plumed.inc.$mode" Plumed.inc
     ln -s "$PLUMED_ROOT/src/lib/Plumed.cmake.$mode" Plumed.cmake
     bash "$diff"
     if type -t plumed_after_patch 1>/dev/null ; then
-      echo "Executing plumed_after_patch function"
+      test -n "$quiet" || echo "Executing plumed_after_patch function"
       plumed_after_patch
     fi
   ;;
   (info)
-    plumed_patch_info 
+    if type -t plumed_patch_info 1>/dev/null ; then
+      test -n "$quiet" || echo "Executing plumed_patch_info function"
+      plumed_patch_info
+    else
+      echo "No special info for this MD engine"
+    fi
   ;;
   (save)
     if [ ! -L Plumed.h -o ! -L Plumed.inc ]
@@ -253,9 +266,9 @@ case "$action" in
       exit
       fi
     fi
-    echo "Saving your changes to $diff"
-    echo "Preplumed files:"
-    echo "$PREPLUMED"
+    test -n "$quiet" || echo "Saving your changes to $diff"
+    test -n "$quiet" || echo "Preplumed files:"
+    test -n "$quiet" || echo "$PREPLUMED"
     test -e "$diff" && rm "$diff"
     for bckfile in $PREPLUMED ; do
       file="${bckfile%.preplumed}"
@@ -281,21 +294,21 @@ EOF
       exit
     fi
     if type -t plumed_before_revert 1>/dev/null ; then
-      echo "Executing plumed_before_revert function"
+      test -n "$quiet" || echo "Executing plumed_before_revert function"
       plumed_before_revert
     fi
     if [ ! -L Plumed.h -o ! -L Plumed.inc ]
     then
       echo "WARNING: I cannot find Plumed.h and Plumed.inc files. You have likely not patched yet."
     else
-    echo "Removing Plumed.h and Plumed.inc"
+    test -n "$quiet" || echo "Removing Plumed.h and Plumed.inc"
       rm Plumed.h Plumed.inc Plumed.cmake
     fi
     PREPLUMED=$(find . -name "*.preplumed")
     if ! test "$PREPLUMED" ; then
       echo "No .preplumed file found, nothing to restore."
     else
-      echo "Reverting changes and touching reverted files"
+      test -n "$quiet" || echo "Reverting changes and touching reverted files"
       for bckfile in $PREPLUMED ; do
         file="${bckfile%.preplumed}"
         mv "$bckfile" "$file"
@@ -303,7 +316,7 @@ EOF
       done
     fi
     if type -t plumed_after_revert 1>/dev/null ; then
-      echo "Executing plumed_after_revert function"
+      test -n "$quiet" || echo "Executing plumed_after_revert function"
       plumed_after_revert
     fi
 esac
diff --git a/user-doc/extract b/user-doc/extract
index 8a795cf34..66e2c5dc6 100755
--- a/user-doc/extract
+++ b/user-doc/extract
@@ -23,7 +23,7 @@ do
    echo "- \subpage $mytag" >> automatic/codes.list
    echo "/**" >> automatic/$myengine.txt
    echo "\page $mytag $myengine" >> automatic/$myengine.txt
-   plumed patch -e $myengine -i | grep -v "PLUMED patching tool" | grep -v "PLUMED location:" | grep -v "extra files located in:" | grep -v "MD engine:" | grep -v "diff file:" | grep -v "sourcing config file:" >> automatic/$myengine.txt
+   plumed patch -e $myengine -i -q >> automatic/$myengine.txt
    echo "*/" >> automatic/$myengine.txt 
 done
 
-- 
GitLab