- Custom
CrabErrorenum withthiserrorcrate - Specific error types for different scenarios:
InvalidProjectName- validation errorsProjectAlreadyExists- duplicate project checkProjectNotFound- missing Crab.toml detectionAuthenticationError- login/auth failuresNetworkError- connection issues with detailed messagesBuildError- compilation failures- And more...
- Exit codes mapped to error types (1-6)
CrabResult<T>type alias for cleaner error handling
-
Colored Output: Using
coloredcrate for beautiful terminal colors- Green for success (✓)
- Red for errors (✗)
- Yellow for warnings (⚠)
- Blue for info (ℹ)
- Cyan for headers
-
Fancy Animations: Using
indicatifcrate- Download animation with spinner
- Build animation
- Cleanup animation
- Upload animation
- Progress bars with percentage display
-
Header Display: ASCII art branding
-
User-Friendly Messages: Consistent, helpful output
-
Project Validation:
validate_project_name()checks for valid naming -
Complete Project Structure: Creates:
/src,/bin,/testsdirectoriesCrab.tomlwith metadatasrc/main.cbstarter file.gitignorefor version controlREADME.mdwith quick-start guide
-
Real Build Logic:
build_project()with animation -
Real Run Logic:
run_project()with dependency simulation -
Cleanup:
clean_project()removes target directory -
Error Propagation: Uses
CrabResultfor proper error handling
- All commands now return
CrabResult<()>for proper error handling - Informative messages before operations
- Test command implementation
- Watch command with file monitoring setup
- Success/failure messages with animations
-
Enhanced Publish:
- Input validation
- Better error messages
- HTTP status handling
- Network error detection (connection, timeout)
-
Login Function: New authentication with token handling
-
Logout Function: Clean session management
-
Structured Responses: Using
PublishResponsestruct
- Added new commands:
login,logout,test,watch - Proper command documentation
- Exit code handling based on error type
- Better version/author info
- Graceful error display and exit
- colored: Terminal colors (v2.1)
- indicatif: Progress bars & animations (v0.17)
- thiserror: Error handling macros (v1.0)
- chrono: Date/time utilities (v0.4)
- serde_json: JSON handling (v1.0)
Comprehensive Error Handling
- Custom error types with exit codes
- User-friendly error messages
- Network error detection and handling
Beautiful CLI Animations
- Spinning progress indicators
- Progress bars with percentage
- Colored output for different message types
Real Project Logic
- Proper directory/file creation
- Project structure validation
- File system operations with error handling
All Commands Supported
init- Initialize in current directorynew- Create new projectbuild- Compile projectrun- Execute projectclean- Remove build artifactstest- Run testswatch- Monitor and rebuildpublish- Upload to registrylogin- Authenticate userlogout- End session
# Create a new project
crab new my-app
# Initialize current directory
crab init
# Build with fancy animation
crab build
# Publish to registry with error handling
crab publish <username> <password>
# Run tests
crab test
# Watch for changes
crab watch
# Login/Logout
crab login <user> <pass>
crab logout| Aspect | Before | After |
|---|---|---|
| Error Handling | println! + unwrap |
Typed errors with exit codes |
| UI/UX | Plain text | Colored output + animations |
| Commands | 5 basic | 8 full-featured |
| Validation | None | Project name validation |
| Project Files | Crab.toml only | Full structure (.gitignore, README, etc.) |
| Network Errors | Generic Error | Detailed error messages |
| User Feedback | Minimal | Comprehensive with animations |