Dan Anglin
95bd888c18
This commit adds a spell checking job to the testing stage of the GitLab CI pipeline. GNU Aspell is used to check the spelling of the JSON CV. The following changes are made in this commit: - created a wrapper script that uses GNU Aspell to check the word spellings in the CV. Errors are printed to the screen. - created a make target to run the spellcheck script. - created a new job in the test stage to run the new make target. - create a custom word list for this project. - corrections made in CV.
79 lines
1.8 KiB
Bash
Executable file
79 lines
1.8 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
ASPELL_LANG='en_GB'
|
|
ASPELL_PERSONAL_WORDLIST='./.aspell/.aspell.en.pws'
|
|
DEFAULT_OUTPUT='aspell_output'
|
|
|
|
RED='\033[1;31m'
|
|
AMBER='\033[1;33m'
|
|
GREEN='\033[1;32m'
|
|
NC='\033[0m'
|
|
|
|
inputFile=''
|
|
outputFile=''
|
|
|
|
usage () {
|
|
echo "Usage:"
|
|
echo "spellcheck [OPTION]..."
|
|
echo
|
|
echo "Description:"
|
|
echo -e "\tspellcheck is a wrapper script that uses aspell to check the spelling of"
|
|
echo -e "\tall words in a file. Any detected spelling errors are printed to screen"
|
|
echo -e "\tand to an output file."
|
|
echo
|
|
echo "Options:"
|
|
echo -e "\t-i\tinput file for spell checking."
|
|
echo -e "\t-o\toutput file where list of spelling errors are written to."
|
|
echo -e "\t\tThe default output file is ${DEFAULT_OUTPUT}."
|
|
echo -e "\t-h\tprints usage."
|
|
echo
|
|
echo -e "Examples:"
|
|
echo -e "\tspellcheck -i my_file.txt -o output.txt"
|
|
echo -e "\tspellcheck -i my_file"
|
|
}
|
|
|
|
validate_args() {
|
|
if [ -z "$inputFile" ]; then
|
|
echo -e "${RED}ERROR: ${NC}Option '-i' is not set or is empty."
|
|
usage
|
|
return 1
|
|
fi
|
|
|
|
if [ -z "$outputFile" ]; then
|
|
echo -e "${AMBER}WARNING: ${NC}Option '-o' is not set or is empty. The output file will be set to ${DEFAULT_OUTPUT}"
|
|
outputFile=${DEFAULT_OUTPUT}
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
spellcheck() {
|
|
cat ${inputFile} | aspell -d ${ASPELL_LANG} -p ${ASPELL_PERSONAL_WORDLIST} list > ${outputFile}
|
|
|
|
let spellingErrors=$( cat ${outputFile} | wc -l )
|
|
if [ $spellingErrors -gt 0 ]; then
|
|
echo
|
|
echo -e "${RED}ERROR: ${NC}The following spelling errors were found in ${inputFile}:"
|
|
cat ${outputFile}
|
|
return 1
|
|
else
|
|
echo
|
|
echo -e "${GREEN}INFO: ${NC}No spelling errors found."
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
while getopts 'i:o:h' flag; do
|
|
case "${flag}" in
|
|
i) inputFile=${OPTARG} ;;
|
|
o) outputFile=${OPTARG} ;;
|
|
h) usage && exit 0 ;;
|
|
*) usage && exit 2 ;;
|
|
esac
|
|
done
|
|
|
|
validate_args || exit 1
|
|
spellcheck || exit 1
|