Command Line Tools
Quick Start Guide
Quick Start Guide
Section titled “Quick Start Guide”Get up and running with Wheels CLI in minutes.
Prerequisites
Section titled “Prerequisites”- CommandBox 5.0+
- Java 8+
- Database (MySQL, PostgreSQL, SQL Server, or H2)
Installation
Section titled “Installation”Install CommandBox
Section titled “Install CommandBox”# macOS/Linuxcurl -fsSl https://downloads.ortussolutions.com/debs/gpg | sudo apt-key add -echo "deb https://downloads.ortussolutions.com/debs/noarch /" | sudo tee -a /etc/apt/sources.list.d/commandbox.listsudo apt-get update && sudo apt-get install commandbox
# Windows (PowerShell as Admin)iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))choco install commandboxInstall Wheels CLI
Section titled “Install Wheels CLI”box install wheels-cliCreating Your First Application
Section titled “Creating Your First Application”1. Generate Application
Section titled “1. Generate Application”wheels new blogcd blogThis creates a new Wheels application with:
- Complete directory structure
- Configuration files
- Sample code
2. Configure Database
Section titled “2. Configure Database”Edit /config/settings.cfm:
<cfset set(dataSourceName="blog_development")>Or use H2 embedded database:
wheels new blog --setupH2Create the database:
# If using external database (MySQL, PostgreSQL, etc.)wheels db create3. Start Server
Section titled “3. Start Server”box server startVisit http://localhost:3000
Creating Your First Feature
Section titled “Creating Your First Feature”Let’s create a blog post feature:
1. Generate Scaffold
Section titled “1. Generate Scaffold”wheels generate scaffold name=post properties=title:string,content:text,published:booleanThis generates:
- Model with validations
- Controller with CRUD actions
- Views for all actions
- Database migration
- Test files
2. Run Migration
Section titled “2. Run Migration”wheels dbmigrate latest3. Add Routes
Section titled “3. Add Routes”Edit /config/routes.cfm:
<cfscript> // Add this line resources("posts");</cfscript>4. Reload Application
Section titled “4. Reload Application”wheels reload5. Test Your Feature
Section titled “5. Test Your Feature”Visit http://localhost:3000/posts
You now have a fully functional blog post management system!
Development Workflow
Section titled “Development Workflow”Running Tests
Section titled “Running Tests”# Run all testswheels test run
# Watch modewheels test run --watch
# Specific testswheels test run tests/models/PostTest.cfcAdding Relationships
Section titled “Adding Relationships”Let’s add comments to posts:
# Generate comment modelwheels generate model comment --properties="author:string,content:text,postId:integer" \ --belongsTo="post"
# Update post modelwheels generate property post comments --has-many
# Generate comments controllerwheels generate controller comments --rest
# Run migrationwheels dbmigrate latestCommon Tasks
Section titled “Common Tasks”Adding Authentication
Section titled “Adding Authentication”# Generate user modelwheels scaffold name=user properties=email:string,password:string,admin:boolean
# Generate session controllerwheels generate controller sessions new,create,delete
# Run migrationswheels dbmigrate latestAdding API Endpoints
Section titled “Adding API Endpoints”# Generate API resourcewheels generate api-resource product --properties="name:string,price:decimal"
# Or convert existing to APIwheels generate controller api/posts --apiWorking with Views
Section titled “Working with Views”# Generate specific viewswheels generate view posts featuredwheels generate view users profile
# Add layoutsecho '<cfoutput><!DOCTYPE html>...</cfoutput>' > views/layout.cfmBest Practices
Section titled “Best Practices”1. Use Migrations
Section titled “1. Use Migrations”Always use migrations for database changes:
# Create tableswheels dbmigrate create table products
# Add columnswheels dbmigrate create column products featured
# Create indexeswheels dbmigrate create blank add_index_to_products2. Write Tests
Section titled “2. Write Tests”Generate tests for your code:
# After creating a modelwheels generate test model post
# After creating a controllerwheels generate test controller posts3. Use Environment Configuration
Section titled “3. Use Environment Configuration”# Developmentwheels reload development
# Testingwheels reload testing
# Productionwheels reload production4. Version Control
Section titled “4. Version Control”git initgit add .git commit -m "Initial Wheels application"Add to .gitignore:
/db/sql//logs//temp/.envDebugging
Section titled “Debugging”Check Logs
Section titled “Check Logs”tail -f logs/wheels.logEnable Debug Mode
Section titled “Enable Debug Mode”In /config/settings.cfm:
<cfset set(showDebugInformation=true)>Common Issues
Section titled “Common Issues”Port already in use:
box server start port=3001Database connection failed:
# Check datasourcebox server infobox server showMigration failed:
# Check statuswheels db status
# Run specific migrationwheels dbmigrate exec 20240120000000
# Or rollback and try againwheels db rollbackNeed to reset database:
# Complete reset (careful - destroys all data!)wheels db reset --forceAccess database directly:
# CLI shellwheels db shell
# Web console (H2 only)wheels db shell --webNext Steps
Section titled “Next Steps”-
Read the Guides:
-
Explore Commands:
wheels --helpwheels generate --helpwheels dbmigrate --help
-
Join the Community:
- Wheels Documentation
- GitHub Discussions
- CFML Slack #wheels channel
Example: Complete Blog Application
Section titled “Example: Complete Blog Application”Here’s a complete blog setup:
# Create applicationwheels new myblog --setupH2cd myblog
# Generate blog structurewheels scaffold post title:string,slug:string,content:text,publishedAt:datetimewheels scaffold author name:string,email:string,bio:textwheels generate model comment author:string,email:string,content:text,postId:integer \ --belongsTo=post
# Update associationswheels generate property post authorId:integer --belongsTo=authorwheels generate property post comments --has-manywheels generate property author posts --has-many
# Add routesecho '<cfset resources("posts")>' >> config/routes.cfmecho '<cfset resources("authors")>' >> config/routes.cfm
# Setup and seed databasewheels db setup --seed-count=10
# Start developmentwheels server start
# Visit http://localhost:3000/postsYou now have a working blog with posts, authors, and comments!