Skip to content
Snippets Groups Projects
Commit 0337774d authored by Jan Frenzel's avatar Jan Frenzel
Browse files

Merge branch 'verbose-flag-for-grep-forbidden-patterns.sh' into 'preview'

Added verbose flag to grep-forbidden-patterns.sh.

See merge request !503
parents ee27e7a4 c69758e4
No related branches found
No related tags found
2 merge requests!530Automated merge from preview to main,!503Added verbose flag to grep-forbidden-patterns.sh.
......@@ -86,7 +86,8 @@ function checkFile(){
fi
IFS=$'\t' read -r flags pattern exceptionPatterns
while IFS=$'\t' read -r -a exceptionPatternsArray; do
if [ $silent = false ]; then
#Prevent patterns from being printed when the script is invoked with default arguments.
if [ $verbose = true ]; then
echo " Pattern: $pattern$skipping"
fi
if [ -z "$skipping" ]; then
......@@ -99,6 +100,7 @@ function checkFile(){
if grep -n $grepflag $color "$pattern" "$f" | grepExceptions "${exceptionPatternsArray[@]}" ; then
number_of_matches=`grep -n $grepflag $color "$pattern" "$f" | grepExceptions "${exceptionPatternsArray[@]}" | wc -l`
((cnt=cnt+$number_of_matches))
#prevent messages when silent=true, only files, pattern matches and the summary are printed
if [ $silent = false ]; then
echo " $message"
fi
......@@ -109,23 +111,29 @@ function checkFile(){
}
function usage () {
echo "$0 [options]"
echo "Search forbidden patterns in markdown files."
echo ""
echo "Options:"
echo " -a Search in all markdown files (default: git-changed files)"
echo " -f Search in a specific markdown file"
echo " -s Silent mode"
echo " -h Show help message"
echo " -c Show git matches in color"
cat <<EOF
$0 [options]
Search forbidden patterns in markdown files.
Options:
-a Search in all markdown files (default: git-changed files)
-f Search in a specific markdown file
-s Silent mode
-h Show help message
-c Show git matches in color
-v verbose mode
EOF
}
# Options
all_files=false
#if silent=true: avoid printing of messages
silent=false
#if verbose=true: print files first and the pattern that is checked
verbose=false
file=""
color=""
while getopts ":ahsf:c" option; do
while getopts ":ahsf:cv" option; do
case $option in
a)
all_files=true
......@@ -140,6 +148,9 @@ while getopts ":ahsf:c" option; do
c)
color=" --color=always "
;;
v)
verbose=true
;;
h)
usage
exit;;
......@@ -162,7 +173,10 @@ else
files=`git diff --name-only "$(git merge-base HEAD "$branch")"`
fi
#Prevent files from being printed when the script is invoked with default arguments.
if [ $verbose = true ]; then
echo "... $files ..."
fi
cnt=0
if [[ ! -z $file ]]; then
checkFile $file
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment