From afd1850fc32ebe7ec25407a141ac667b63efed91 Mon Sep 17 00:00:00 2001 From: Andrew Gazelka Date: Tue, 1 Oct 2024 14:02:31 -0700 Subject: [PATCH] improve --- tools/run_cargo_machete.sh | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/tools/run_cargo_machete.sh b/tools/run_cargo_machete.sh index 5c86ec4cf2..c56f139957 100755 --- a/tools/run_cargo_machete.sh +++ b/tools/run_cargo_machete.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e # ANSI color codes RED='\033[0;31m' @@ -6,17 +7,20 @@ YELLOW='\033[1;33m' GREEN='\033[0;32m' NC='\033[0m' # No Color +# Function to print colored messages +print_message() { + local color=$1 + local message=$2 + echo -e "${color}${message}${NC}" +} + # Check if cargo-machete is installed -if ! command -v cargo-machete &> /dev/null -then - echo -e "${YELLOW}Warning: cargo-machete could not be found${NC}" - echo -e "${YELLOW}To install, run: ${GREEN}cargo install cargo-machete${NC}" - echo -e "${YELLOW}Skipping cargo-machete check${NC}" -else - # Run cargo-machete with the --with-metadata flag - echo -e "${GREEN}Running cargo-machete...${NC}" - cargo machete --with-metadata -fi +command -v cargo-machete >/dev/null 2>&1 || { + print_message "$YELLOW" "Warning: cargo-machete could not be found" + print_message "$YELLOW" "To install, run: cargo install cargo-machete" + print_message "$RED" "Exiting due to missing cargo-machete" + exit 1 +} -# Always exit with 0 to not fail -exit 0 +# Run cargo-machete +cargo machete --with-metadata