From 0d536bd680cc32a6b660a62f6960b29821fc5816 Mon Sep 17 00:00:00 2001 From: Mikhail Epatko Date: Sun, 10 Mar 2024 17:14:45 +0300 Subject: [PATCH] #9 Added multiline values into exclude option --- README.md | 17 ++++++++++------- generate-badge.sh | 9 +++++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 27fbb52..894b815 100644 --- a/README.md +++ b/README.md @@ -25,14 +25,17 @@ jobs: steps: - uses: actions/checkout@v4 - id: badge-generator - uses: ./ # write the action name instead + uses: ./ # Write the action name instead. with: - before: 2024-03-03' # default value - now day - dir: . # default value - include all files - exclude: vendor/** # no default value - since: 2000-01-01 # default value - '2000-01-01' - output_dir: ./output # default value - 'output' - filename: hoc-badge.svg # default value - 'hoc-badge.svg' + since: 2000-01-01 # Default value: '2000-01-01'. + before: 2024-03-03' # Default value: now day. + dir: . # Default value: include all files in the current directory. + exclude: |- # We can use multiline strings if we want something close to multiline values. + dir1/** ## It's an important detail that we used '|-' in the YAML and not '|'. + dir2/**/* ## There is no default value for exclude option. + dir3/file.txt + output_dir: ./output # Default value: './output'. + filename: hoc-badge.svg # Default value: 'hoc-badge.svg'. ``` The badge will be generated into the file ./output/hoc-badge.svg by default. diff --git a/generate-badge.sh b/generate-badge.sh index 7b4f7b2..48d25f3 100755 --- a/generate-badge.sh +++ b/generate-badge.sh @@ -33,13 +33,18 @@ while getopts 'b:d:e:f:o:s:' opt; do done if [ "$Before" == '[]' ]; then Before="$(date +%F)"; fi -if [ "$Excld" != '[]' ]; then Exclude="$Excld"; fi +if [ "$Excld" != '[]' ]; then + IFS=$'\n' read -rd '' -a array <<< "$Excld" + for word in "${array[@]}"; do + Exclude="${Exclude} -e $word" + done +fi echo "$Dir ${Exclude[*]} $Since $Before" mkdir -p "$OutDir" -Count=$(hoc -d "$Dir" ${Exclude:+"-e ${Exclude[@]}"} -e "${Exclude[@]}" -s "$Since" -b "$Before" -f "int") +Count=$(hoc -d "$Dir" ${Exclude:+${Exclude[@]}} -s "$Since" -b "$Before" -f "int") echo "Hits of code: $Count" anybadge -l "Hits of Code" -v "$Count" -f "$OutDir/$Filename" -c royalblue