#!/bin/bash USAGE="test_data.sh root-path data-path data-format total-entries out-format" [ "$1" == "-h" ] && echo "$USAGE" && exit [ -n "$1" ] && DATA_PATH=$1 if [ -z "$DATA_PATH" ] && [ -r "." ] ; then DATA_PATH="." DATA_TARGET="data.yaml" DATA_FORMAT="yaml" fi [ ! -d "$DATA_PATH" ] && echo "Root path: $DATA_PATH not found" && DATA_PATH="" [ -z "$DATA_PATH" ] && echo -n "Root path for data: " && read -r DATA_PATH && echo "" [ -n "$2" ] && DATA_TARGET=$2 [ ! -r "$DATA_PATH/$DATA_TARGET" ] && echo "Target path: $DATA_TARGET not found in $DATA_PATH" && DATA_TARGET="" [ -z "$DATA_TARGET" ] && echo -n "Path for target data: " && read -r DATA_TARGET && echo "" [ -n "$3" ] && [ -z "$DATA_FORMAT" ] && DATA_FORMAT=$3 DATA_TARGET=$(echo "$DATA_TARGET" | cut -f1 -d".") format=$(basename "$DATA_TARGET" | cut -f2 -d".") if [ -z "$DATA_FORMAT" ] ;then echo -ne "Path: $DATA_PATH\nformat (yaml,toml,json): $format [ENTER or change] " read -r DATA_FORMAT && echo "" fi case "$DATA_FORMAT" in yaml|YAML) DATA_FORMAT="yaml" ;; toml|TOML) DATA_FORMAT="toml" ;; json|JSON) DATA_FORMAT="json" ;; *) DATA_FORMAT=$format # echo "Format \"$DATA_FORMAT\" not defined" && exit 1 esac [ -n "$4" ] && DATA_TOTAL=$4 if [ -z "$DATA_TOTAL" ] ; then echo -ne "Expected NUMBER or items to be loaded from\npath: $DATA_PATH\nwith format $DATA_FORMAT [number]: " read -r DATA_TOTAL [[ ! $DATA_TOTAL =~ ^[[:digit:]]+$ ]] && echo "DATA_TOTAL not a number" && exit 1 fi [ -n "$5" ] && DATA_OUT_FORMAT=$5 out_format="" if [ -z "$DATA_OUT_FORMAT" ] ;then echo -ne "Path: $DATA_LANG_PATH\nOUTPUT format (yaml,toml,json): $out_format [ENTER or change] " read -r DATA_OUT_FORMAT && echo "" fi case "$DATA_OUT_FORMAT" in yaml|YAML) DATA_OUT_FORMAT="yaml" ;; toml|TOML) DATA_OUT_FORMAT="toml" ;; json|JSON) DATA_OUT_FORMAT="json" ;; -) DATA_OUT_FORMAT="" ;; *) echo "Format \"$DATA_LANG_FORMAT\" " #DATA_OUT_FORMAT=$out_format esac export DATA_PATH export DATA_TARGET export DATA_FORMAT export DATA_TOTAL export DATA_OUT_FORMAT cargo test load_data -- --nocapture