fix scripts
This commit is contained in:
@@ -8,5 +8,6 @@ members = [
|
|||||||
"loops",
|
"loops",
|
||||||
"ownership",
|
"ownership",
|
||||||
"references_and_borrowing",
|
"references_and_borrowing",
|
||||||
|
"slice_type",
|
||||||
"variables",
|
"variables",
|
||||||
]
|
]
|
||||||
|
@@ -5,23 +5,28 @@ set -e
|
|||||||
name="$1"
|
name="$1"
|
||||||
|
|
||||||
if [ -z "$name" ]; then
|
if [ -z "$name" ]; then
|
||||||
echo "❌ Usage: ./monorepo-cargo-new.sh <project_name>"
|
echo "❌ Usage: ./create_project.sh <project_name>"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Step 1: Create new cargo project without initializing Git
|
# Step 1: Create new cargo project without Git
|
||||||
cargo new "$name" --vcs none
|
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
|
if grep -q "^\[workspace\]" Cargo.toml; then
|
||||||
# Avoid duplicate entries
|
|
||||||
if grep -q "\"$name\"" Cargo.toml; then
|
if grep -q "\"$name\"" Cargo.toml; then
|
||||||
echo "⚠️ Project '$name' already exists in workspace members. Skipping insertion."
|
echo "⚠️ Project '$name' already exists in workspace members. Skipping insertion."
|
||||||
else
|
else
|
||||||
echo "📦 Adding '$name' to workspace members..."
|
echo "📦 Adding '$name' to workspace members..."
|
||||||
|
|
||||||
# Insert before the closing bracket of members array
|
# Find the line number of the closing bracket ]
|
||||||
sed -i "/members\s*=\s*\[/,/]/ s/^\(\s*\)\]/ \"$name\",\n\1]/" Cargo.toml
|
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
|
fi
|
||||||
else
|
else
|
||||||
echo "❌ No [workspace] section found in Cargo.toml."
|
echo "❌ No [workspace] section found in Cargo.toml."
|
||||||
@@ -29,4 +34,3 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "✅ Project '$name' created and added to workspace!"
|
echo "✅ Project '$name' created and added to workspace!"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user