${Indent}Last list refresh: $(date)
${Indent}
EOF
} # UpdatingRemarks()
function MakeVersionListFile() {
# Writes a HTML file on screen
local -r TemplateFilePath="$1"
local -r DocDir="$2"
#
# write a header comment
#
cat <
EOC
#
# "parse" the template
#
# the horror...
local Line
local OldIFS="$IFS"
IFS=''
while read Line ; do
if [[ "$Line" =~ ${VersionListTag} ]]; then # replace this line
MakeHTMLlist "$DocDir"
elif [[ "$Line" =~ ${UpdateTag} ]]; then # replace this line
UpdatingRemarks
else
# trying hard to avoid any reinterpretation; `echo` *might* have sufficed
cat <<< "$Line"
fi
done < "$TemplateFilePath"
IFS="$OldIFS"
} # MakeVersionListFile()
# ------------------------------------------------------------------------------
#
# argument parsing
#
declare -i NoMoreOptions
declare -i DoVersion=0 DoHelp=0
declare -i CleanOutputArea=0 UpdateOutputArea=0
declare TemplateFileName="$DefaultTemplateFileName"
declare VersionListTag="$DefaultVersionListTag"
declare UpdateTag="$DefaultUpdateTag"
declare ExitWithCode
declare Param
for (( iParam = 1 ; iParam <= $# ; ++iParam )); do
Param="${!iParam}"
if isFlagUnset NoMoreOptions && [[ "${Param:0:1}" == '-' ]]; then
case "$Param" in
( '--experiment='* ) ExperimentName="${Param#--*=}" ;;
( '--outputfile='* ) DestFile="${Param#--*=}" ;;
( '--reponame='* ) ExperimentCodeName="${Param#--*=}" ;;
( '--version' | '-V' ) DoVersion=1 ;;
( '--help' | '-h' | '-?' ) DoHelp=1 ;;
( '-' | '--' ) NoMoreOptions=1 ;;
( * )
ERROR "Unknown option: '${Param}'."
ExitWithCode=1
esac
else
PositionalArguments+=( "$Param" )
fi
done
[[ "${#PositionalArguments[@]}" -gt 0 ]] && FATAL 1 "Found ${#PositionalArguments[@]} spurious arguments on command line: ${PositionalArguments[@]}."
: ${ExperimentName:="$(FindExperiment)"}
: ${ExperimentCodeName:="$(ExperimentCodeProduct "$ExperimentName")"}
if isFlagSet DoVersion ; then
printVersion
[[ -z "$ExitWithCode" ]] && ExitWithCode=0
fi
if isFlagSet DoHelp ; then
printHelp
[[ -z "$ExitWithCode" ]] && ExitWithCode=0
fi
[[ -n "$ExitWithCode" ]] && exit "$ExitWithCode"
#
# checks
#
# (some checks are delayed because they are not fatal when just printing help)
#
[[ -n "$ExperimentName" ]] || FATAL 1 "Can't detect the experiment name."
[[ -n "$ExperimentCodeName" ]] || FATAL 1 "Can't put together the experiment code repository name for '${ExperimentName}'."
declare TemplateFilePath="${SCRIPTDIR%/}/${TemplateFileName}"
[[ -r "$TemplateFilePath" ]] || FATAL 2 "Can't find template file '${TemplateFileName}' in '${SCRIPTDIR}'."
# not controlled by option because used only to compose `DestFile`:
PublishDir="${PublishBaseDir%/}/${ExperimentCodeName}"
[[ -r "$PublishDir" ]] || FATAL 2 "Can't find publishing base directory '${PublishDir}'."
# set a default destination if needed
: ${DestFile:="${PublishDir%/}/${VersionListFile}"}
#
# write the HTML file
#
if [[ -e "$DestFile" ]]; then
echo "Overwriting: '${DestFile}'"
else
echo "Writing: '${DestFile}'"
fi
MakeVersionListFile "$TemplateFilePath" "$PublishDir" > "$DestFile"