From f48cfd00565930e278746fde68117246566aac93 Mon Sep 17 00:00:00 2001 From: Amoelle Date: Tue, 1 Jul 2025 15:15:13 +0300 Subject: [PATCH] fix scripts --- Cargo.toml | 1 + create_project.sh | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 171cfa5..a72205e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,5 +8,6 @@ members = [ "loops", "ownership", "references_and_borrowing", + "slice_type", "variables", ] diff --git a/create_project.sh b/create_project.sh index 77d0b62..aa0047c 100755 --- a/create_project.sh +++ b/create_project.sh @@ -5,23 +5,28 @@ set -e name="$1" if [ -z "$name" ]; then - echo "❌ Usage: ./monorepo-cargo-new.sh " + echo "❌ Usage: ./create_project.sh " exit 1 fi -# Step 1: Create new cargo project without initializing Git +# Step 1: Create new cargo project without Git cargo new "$name" --vcs none -# Step 2: Insert the project into the [workspace] members list in Cargo.toml +# Step 2: Insert project into workspace 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 + # Find the line number of the closing bracket ] + end_line=$(awk '/members\s*=\s*\[/,/\]/{if ($0 ~ /\]/) print NR}' Cargo.toml) + + # Insert before the closing bracket + awk -v name="$name" -v end="$end_line" ' + NR == end { print " \"" name "\"," } + { print } + ' Cargo.toml > Cargo.toml.tmp && mv Cargo.toml.tmp Cargo.toml fi else echo "❌ No [workspace] section found in Cargo.toml." @@ -29,4 +34,3 @@ else fi echo "✅ Project '$name' created and added to workspace!" -