diff --git a/pre-commit-hooks/rust-fmt.sh b/pre-commit-hooks/rust-fmt.sh index a848185..a2bac9b 100755 --- a/pre-commit-hooks/rust-fmt.sh +++ b/pre-commit-hooks/rust-fmt.sh @@ -3,9 +3,13 @@ # Exit immediately if a command exits with a non-zero status set -e +# Get the directory to run cargo fmt in, default to current directory +RUST_DIR=${1:-.} + # Function to format rust code run_cargo_fmt() { echo "Executing 'cargo fmt'" + cd "$RUST_DIR" cargo fmt } diff --git a/pre-commit-hooks/rust-lint.sh b/pre-commit-hooks/rust-lint.sh index e0b9340..1746eac 100755 --- a/pre-commit-hooks/rust-lint.sh +++ b/pre-commit-hooks/rust-lint.sh @@ -3,12 +3,16 @@ # Exit immediately if a command exits with a non-zero status. set -e +# Get the directory to run cargo fmt in, default to current directory +RUST_DIR=${1:-.} + # Function to run linters on the rust project run_linter() { echo "Executing clippy" # Run the linter and capture the exit status set +e + cd "$RUST_DIR" cargo clippy -- -D warnings local linting_result=$? set -e