set -Eeuo pipefail
APP_NAME="definition (CSV) to file listing converter"
function print_help() {
script_name="$(basename "$0")"
echo -e ""
echo -e "$APP_NAME - Given a definition.csv (as found in mod/*/definition.csv')"
echo -e "generates a simple file listing."
echo -e "Basically, it just extracts the first column without the header"
echo -e "The input files first column has to follow these rules:"
echo -e "* one file/dir per line"
echo -e "* full paths, relative to the output-dir"
echo -e "* each line indicating a dir needs to end with a '/'"
echo -e "* empty lines and lines starting with '#' or ';', are ignored"
echo -e "* any other line indicates a file"
echo -e ""
echo -e "Usage:"
echo -e "\t$script_name [OPTION...] <definition-csv-file>"
echo -e "Options:"
echo -e "\t-h, --help"
echo -e "\t\tPrint this usage help and exit"
echo -e "Examples:"
echo -e "\t$script_name mod/unixish/definition.csv"
echo -e ""
}
while [[ $# -gt 0 ]]
do
arg="$1"
shift
case "$arg" in
-h|--help)
print_help
exit 0
;;
-*) >&2 echo "ERROR: Unknown switch '$arg'"
exit 1
;;
*) POSITIONAL+=("$arg") ;;
esac
done
set -- "${POSITIONAL[@]}"
if [ -z "${1:-}" ]
then
>&2 echo "ERROR: Please supply path to input file (definition.csv)."
exit 1
fi
input_file="$1"
tail -n +2 "$input_file" | while IFS= read -r line
do
if [ -z "$line" ] || [[ $line =~ ^[#\;].* ]]
then
continue
fi
if [[ $line =~ ^\" ]]
then
echo "$line" | sed -e 's|^"||' -e 's|",.*||'
else
echo "${line%%,*}"
fi
done