esh 0.1.1

Embeddable SHell - a Rust library for building interactive, command-driven CLI applications.
Documentation
#!/bin/bash

CMD=$(basename "$0")

warn () { echo "$CMD: $*" >&2; }
die  () { echo "$CMD: $*" >&2; exit 1; }

warn "🚀 Running Pre-Commit Checks"

# BRANCH=$(git rev-parse --abbrev-ref HEAD)
# if [[ "$BRANCH" == "main" || "$BRANCH" == "master" ]]; then
#   warn "❌ ERROR: You are trying to commit directly to the '$BRANCH' branch."
#   die "Please use a feature branch and a Pull Request instead."
# fi

# Check Formatting
make check
if [ $? -ne 0 ]; then
    die "❌ Formatting or Clippy failed. Fix errors before committing."
fi

# Run Tests
make test-quiet
if [ $? -ne 0 ]; then
    die "❌ Tests failed. Fix errors before committing."
fi

# Run Security Audit
make audit
if [ $? -ne 0 ]; then
    die "❌ Security audit failed! Check your dependencies."
fi

# Extract MSRV from Cargo.toml
MSRV=$(grep -m 1 '^rust-version' Cargo.toml | cut -d '"' -f 2)

if [ -z "$MSRV" ]; then
    die "No rust-version found in Cargo.toml. Skipping MSRV check."
fi

warn "Checking MSRV compatibility ($MSRV)..."

# Run cargo check using the specific toolchain
# --profile dev is faster; --locked ensures we use the existing lockfile
rustup run "$MSRV" cargo check --locked --profile dev

if [ $? -ne 0 ]; then
    die "MSRV Check Failed! Please fix compatibility issues before committing."
fi

warn "✅ All checks passed. Committing..."
exit 0