Repository navigation
Expand file tree
/
Copy pathrust-new.sh
More file actions
executable file
·77 lines (60 loc) · 1.85 KB
/
Copy pathrust-new.sh
File metadata and controls
executable file
·77 lines (60 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
# ┃ rust-new — Hamze's Rust Bootstrap ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
# Scaffolds a Rust project from your template
# Adds private GitHub repo via post_gen.sh
#
# Usage:
# rust-new <project-name>
# rust-new --help
set -euo pipefail
### --- Constants ---
TEMPLATE_REPO="https://github.com/hghalebi/rust_template.git"
### --- Help Message ---
print_help() {
cat <<EOF
🦀 rust-new: Create a new Rust project from Hamze's template
USAGE:
rust-new <project-name>
DESCRIPTION:
This script scaffolds a new Rust project from the template:
$TEMPLATE_REPO
It automatically runs post_gen.sh to:
- Initialize Git
- Create a private GitHub repo
- Push your first commit
REQUIREMENTS:
- cargo-generate
- gh (GitHub CLI) authenticated
- Internet access
EXAMPLE:
rust-new my-cli-tool
FLAGS:
-h, --help Show this help message
EOF
}
### --- Handle Help Flag ---
if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
print_help
exit 0
fi
### --- Validate Project Name ---
if [[ $# -lt 1 ]]; then
echo "❌ Error: Project name required."
echo "➡️ Try: rust-new --help"
exit 1
fi
PROJECT_NAME="$1"
### --- Run cargo-generate ---
echo "🛠 Creating project '$PROJECT_NAME' from template..."
cargo generate --git "$TEMPLATE_REPO" --name "$PROJECT_NAME"
cd "$PROJECT_NAME"
### --- Run post_gen.sh if exists ---
if [[ -f "./post_gen.sh" ]]; then
echo "🚀 Running post_gen.sh to create GitHub repo..."
./post_gen.sh
else
echo "⚠️ post_gen.sh not found, skipping GitHub repo creation."
fi
echo "✅ Done! Your new Rust project '$PROJECT_NAME' is ready. 🚀"