Skip to content

Commit

Permalink
improve cargo-machete script
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgazelka committed Oct 1, 2024
1 parent 111c1e4 commit ba9adbb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
17 changes: 8 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ repos:
types: [rust]
args: [--]

- id: cargo-machete
name: cargo machete
description: Check for unused Rust dependencies
entry: ./tools/run_cargo_machete.sh
language: system
types: [rust]
pass_filenames: false

- id: cargo-check-default
name: cargo check (default)
description: Check the package for errors with default features.
Expand Down Expand Up @@ -110,15 +118,6 @@ repos:
types: [rust]
pass_filenames: false

- id: cargo-machete
name: cargo machete
description: Check for unused Rust dependencies
entry: cargo machete
language: system
types: [rust]
pass_filenames: false
args: [--with-metadata]

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.19
hooks:
Expand Down
20 changes: 20 additions & 0 deletions tools/run_cargo_machete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# ANSI color codes
RED='\033[0;31m'
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

# Check if cargo-machete is installed
if ! command -v cargo-machete &> /dev/null
then
echo -e "${RED}Error: cargo-machete could not be found${NC}"
echo -e "${YELLOW}To install, run: ${GREEN}cargo install cargo-machete${NC}"
echo -e "${YELLOW}For more information, visit: ${GREEN}https://github.com/bnjbvr/cargo-machete${NC}"
exit 1
fi

# Run cargo-machete with the --with-metadata flag
echo -e "${GREEN}Running cargo-machete...${NC}"
cargo machete --with-metadata

0 comments on commit ba9adbb

Please sign in to comment.