rspec/ci/replace_variables_in_path.sh
Fred Tingaud 83c54f9795
Handle variables *inside* an include
The point of this branch is the second commit that changes
validate_asciidoc.sh. The first one is taken from another PR and should
not be reviewed.

The previous version of the validation could handle the following case:
```asciidoc
:path: path/to/file.adoc
include::{path}[]
```

This new validation also adds support for the case of a variable inside
a path:
```asciidoc
:language: csharp
include::rules/S1000/{language}/file.adoc[]
```
2023-06-22 11:45:41 +02:00

26 lines
881 B
Bash
Executable File

#!/bin/bash
set -uoe pipefail
if [ "$#" -ne 2 ]; then
echo "Usage: $0 VARS_FILE INCLUDE_TEXT"
echo " This script should be called by validate_asciidoc.sh."
echo " When provided with an include that contains one variable part, will"
echo " output all possible values for this include."
echo ""
echo " VARS_FILE: a text file listing all variables as \"name\tvalue\""
echo ""
echo " INCLUDE_TEXT: the whole include declaration"
exit 1
fi
if echo "$2" | grep -Eq "\{.*\{" ; then
echo "Multiple variables detected in \"$2\" this is not supported"
exit 2
fi
BEFORE=$(echo "$2" | sed -r "s/include::(.*)\{(.*)\}(.*)\[\]/\1/")
VAR=$(echo "$2" | sed -r "s/include::(.*)\{(.*)\}(.*)\[\]/\2/")
AFTER=$(echo "$2" | sed -r "s/include::(.*)\{(.*)\}(.*)\[\]/\3/")
grep "${VAR}" "$1" | cut -f2 | xargs -I@ echo "${BEFORE}@${AFTER}"