#!/bin/bash set -e name="$1" if [ -z "$name" ]; then echo "❌ Usage: ./monorepo-cargo-new.sh " exit 1 fi # Step 1: Create new cargo project without initializing Git cargo new "$name" --vcs none # Step 2: Insert the project into the [workspace] members list in Cargo.toml if grep -q "^\[workspace\]" Cargo.toml; then # Avoid duplicate entries if grep -q "\"$name\"" Cargo.toml; then echo "⚠️ Project '$name' already exists in workspace members. Skipping insertion." else echo "📦 Adding '$name' to workspace members..." # Insert before the closing bracket of members array sed -i "/members\s*=\s*\[/,/]/ s/^\(\s*\)\]/ \"$name\",\n\1]/" Cargo.toml fi else echo "❌ No [workspace] section found in Cargo.toml." exit 1 fi echo "✅ Project '$name' created and added to workspace!"