zinzen 0.3.1

Algorithm for auto-scheduling time-constrained tasks on a timeline
#!/usr/bin/env bash

set -au

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
LOG_BASE="${SCRIPT_DIR}/../_logs"
ZIN_BASE="${SCRIPT_DIR}/../Cargo.toml"
PARAM=${1:-""}
CARGO_MANIFEST_DIR=$ZIN_BASE

CURRENTDATE=$(date +"%Y-%m-%d--%H-%M")

if [[ ! -d "$LOG_BASE" ]]; then
    mkdir -p "$LOG_BASE"
fi

if [[ "${PARAM}" == "--help" || "${PARAM}" == "-h" ]]; then
    echo "Usage: $0 [PARAM]"
    echo ""
    echo "  PARAM: [Optional] add test case name to be passed to cargo test"
    echo ""
    echo "Example: $0 my_test_case"
    echo "  Runs the cargo test command with the 'my_test_case' parameter"
    echo "  and saves the output to a log file in the _logs directory."
    echo ""
    exit 0
elif [[ "${PARAM}" == "" ]]; then
    # Update FILE_NAME and LOG_FILE to avoid PARAM inside it
    FILE_NAME="test_${CURRENTDATE}.log"
    LOG_FILE="${LOG_BASE}/${FILE_NAME}"

    touch "$LOG_FILE"
    echo "COMMAND: cargo test --no-fail-fast --manifest-path ${ZIN_BASE} >> ${LOG_FILE}" >> "$LOG_FILE"
    cargo test --no-fail-fast --manifest-path "$ZIN_BASE" >> "$LOG_FILE"
    exit
else
    # Update FILE_NAME and LOG_FILE to include PARAM inside it
    FILE_NAME="test_${PARAM}_${CURRENTDATE}.log"
    LOG_FILE="${LOG_BASE}/${FILE_NAME}"
    RUST_LOG=debug

    touch "$LOG_FILE"
    echo "COMMAND: RUST_LOG=debug cargo test --no-fail-fast --manifest-path ${ZIN_BASE} ${PARAM} >> ${LOG_FILE}" > "$LOG_FILE"
    # cargo test --manifest-path "$ZIN_BASE" "$PARAM" -- --nocapture >> "$LOG_FILE"
    RUST_LOG=debug cargo test --manifest-path "$ZIN_BASE" "$PARAM" 2>&1 | tee -a "$LOG_FILE"
    exit
fi