major changes
- Added documentation via mdbook - Created basic VS code extension - Implemented if else blocks and changed some syntax - fixed some issues
This commit is contained in:
172
docs/src/getting-started/quick-start.md
Normal file
172
docs/src/getting-started/quick-start.md
Normal file
@@ -0,0 +1,172 @@
|
||||
# Quick Start
|
||||
|
||||
> ⚠️ This documentation is AI-generated and may contain errors.
|
||||
|
||||
This guide will walk you through creating your first Rush script.
|
||||
|
||||
## Your First Script
|
||||
|
||||
Create a file called `hello.rsh`:
|
||||
|
||||
```rush
|
||||
#!/usr/bin/env rush
|
||||
|
||||
# Variables are assigned with =
|
||||
NAME = "Rush"
|
||||
echo "Hello from $NAME!"
|
||||
```
|
||||
|
||||
Run it:
|
||||
```bash
|
||||
rush hello.rsh
|
||||
```
|
||||
|
||||
Output:
|
||||
```
|
||||
Hello from Rush!
|
||||
```
|
||||
|
||||
## Variables and Interpolation
|
||||
|
||||
Variables are automatically interpolated in strings:
|
||||
|
||||
```rush
|
||||
PROJECT = "my-app"
|
||||
VERSION = "1.0.0"
|
||||
FULL_NAME = "$PROJECT-v$VERSION"
|
||||
|
||||
echo "Building $FULL_NAME"
|
||||
# Output: Building my-app-v1.0.0
|
||||
```
|
||||
|
||||
## Using Built-in Variables
|
||||
|
||||
Rush provides several built-in variables:
|
||||
|
||||
```rush
|
||||
echo "Current user: $USER"
|
||||
echo "Home directory: $HOME"
|
||||
|
||||
if $IS_ROOT {
|
||||
echo "Running as root"
|
||||
} else {
|
||||
echo "Running as normal user"
|
||||
}
|
||||
```
|
||||
|
||||
## Conditional Logic
|
||||
|
||||
Use `if`/`else` for branching:
|
||||
|
||||
```rush
|
||||
ENV = "production"
|
||||
|
||||
if $ENV {
|
||||
echo "Environment: $ENV"
|
||||
}
|
||||
|
||||
if not $IS_ROOT {
|
||||
echo "Warning: Not running as root"
|
||||
} else {
|
||||
echo "Running with elevated privileges"
|
||||
}
|
||||
```
|
||||
|
||||
## Loops
|
||||
|
||||
Iterate over items with `for`:
|
||||
|
||||
```rush
|
||||
# Loop over space-separated items
|
||||
for name in Alice Bob Charlie {
|
||||
echo "Hello, $name!"
|
||||
}
|
||||
|
||||
# Use variables in loops
|
||||
SERVERS = "web-1 web-2 web-3"
|
||||
for server in web-1 web-2 web-3 {
|
||||
echo "Deploying to $server"
|
||||
}
|
||||
```
|
||||
|
||||
## Parallel Execution
|
||||
|
||||
Run tasks concurrently:
|
||||
|
||||
```rush
|
||||
parallel {
|
||||
run {
|
||||
echo "Task 1: Starting..."
|
||||
echo "Task 1: Complete"
|
||||
}
|
||||
|
||||
run {
|
||||
echo "Task 2: Starting..."
|
||||
echo "Task 2: Complete"
|
||||
}
|
||||
|
||||
run {
|
||||
echo "Task 3: Starting..."
|
||||
echo "Task 3: Complete"
|
||||
}
|
||||
}
|
||||
|
||||
echo "All tasks finished"
|
||||
```
|
||||
|
||||
The output from parallel blocks may be interleaved since they run concurrently.
|
||||
|
||||
## A Complete Example
|
||||
|
||||
Here's a more complete script showing multiple features:
|
||||
|
||||
```rush
|
||||
#!/usr/bin/env rush
|
||||
|
||||
# Configuration
|
||||
PROJECT = "web-app"
|
||||
ENV = "staging"
|
||||
DEPLOY_DIR = "/var/www/$PROJECT"
|
||||
|
||||
echo "Deployment Script for $PROJECT"
|
||||
echo "Environment: $ENV"
|
||||
echo ""
|
||||
|
||||
# Pre-flight checks
|
||||
if not $IS_ROOT {
|
||||
echo "Warning: Not root. Some operations may fail."
|
||||
}
|
||||
|
||||
# Build steps
|
||||
echo "Running build steps:"
|
||||
for step in lint test build {
|
||||
echo " - $step"
|
||||
}
|
||||
|
||||
# Deploy to multiple servers in parallel
|
||||
echo ""
|
||||
echo "Deploying to $ENV servers..."
|
||||
|
||||
parallel {
|
||||
run {
|
||||
echo "[server-1] Deploying $PROJECT"
|
||||
echo "[server-1] Complete"
|
||||
}
|
||||
|
||||
run {
|
||||
echo "[server-2] Deploying $PROJECT"
|
||||
echo "[server-2] Complete"
|
||||
}
|
||||
}
|
||||
|
||||
echo ""
|
||||
echo "Deployment complete!"
|
||||
```
|
||||
|
||||
## Next Steps
|
||||
|
||||
Learn more about Rush's features:
|
||||
- [Variables](../language/variables.md) - Deep dive into variable handling
|
||||
- [Control Flow](../language/control-flow.md) - Conditionals and branching
|
||||
- [Loops](../language/loops.md) - Iteration patterns
|
||||
- [Parallel Execution](../language/parallel.md) - Concurrency in Rush
|
||||
Reference in New Issue
Block a user