wheels get environment
Overview
The wheels get environment
command displays the current environment setting for your Wheels application. It automatically detects which environment your application is configured to run in (development, staging, production, etc.) and shows where this configuration is coming from.
Command Syntax
wheels get environment
Alias
wheels get env
Parameters
This command takes no parameters.
Basic Usage
Display Current Environment
wheels get environment
This will output something like:
Current Environment:
development
Configured in: .env file (WHEELS_ENV)
How It Works
Detection Priority
The command checks for environment configuration in the following order of precedence:
.env
file - Looks forWHEELS_ENV
variable first, thenEnvironment
variableSystem environment variable - Checks for
WHEELS_ENV
first, thenEnvironment
system variableDefault - Falls back to
development
if no configuration is found
The first valid configuration found is used and reported, along with which specific variable name was found.
Configuration Sources
1. .env File
The command first looks for a WHEELS_ENV
variable in your application's .env
file:
# .env file - Primary variable
WHEELS_ENV=production
DATABASE_HOST=localhost
If WHEELS_ENV
is not found, it then checks for Environment
:
# .env file - Alternative variable
Environment=staging
DATABASE_HOST=localhost
The regex pattern used ensures it correctly reads the value while ignoring:
Comments after the value (anything after
#
)Trailing whitespace
Lines that are commented out
2. System Environment Variable
If not found in .env
, it checks for system-level environment variables in the same order:
# Linux/Mac - Primary variable
export WHEELS_ENV=staging
# Windows - Primary variable
set WHEELS_ENV=staging
# Or using the alternative variable
export Environment=production
3. Default Value
If no configuration is found anywhere, it defaults to development
.
Variable Priority
The command checks for two different variable names in this specific order:
WHEELS_ENV
in.env
fileEnvironment
in.env
fileWHEELS_ENV
system environment variableEnvironment
system environment variableDefault to
development
Output Examples
Configured with WHEELS_ENV in .env
Current Environment:
production
Configured in: .env file (WHEELS_ENV)
Configured with Environment in .env
Current Environment:
staging
Configured in: .env file (Environment)
Configured via System Variable (WHEELS_ENV)
Current Environment:
staging
Configured in: System environment variable (WHEELS_ENV)
Configured via System Variable (Environment)
Current Environment:
production
Configured in: System environment variable (Environment)
Using Default
Current Environment:
development
Configured in: Using default
Common Use Cases
Verify Environment Before Deployment
# Check environment before starting server
wheels get environment
commandbox server start
Troubleshooting Configuration Issues
# Verify which configuration source and variable is being used
wheels get environment
# Check each source manually
cat .env | grep -E "WHEELS_ENV|Environment"
echo $WHEELS_ENV
echo $Environment
CI/CD Pipeline Verification
# In deployment script
wheels get environment
if [ $? -eq 0 ]; then
echo "Environment configured successfully"
fi
Supporting Legacy Systems
# If migrating from a system that uses "Environment" variable
# Both will work without changes:
# Old: Environment=production
# New: WHEELS_ENV=production
wheels get environment
Error Handling
The command will show an error if:
It's not run from a Wheels application directory
There's an error reading configuration files
File permissions prevent reading configuration
Not a Wheels Application
Error: This command must be run from a Wheels application directory
Read Error
Error reading environment: [specific error message]
Best Practices
Use WHEELS_ENV - Prefer
WHEELS_ENV
overEnvironment
for clarity and consistencyConsistent Configuration - Use one primary method for setting environment across your team
Environment-Specific Files - Consider using
.env.production
,.env.development
files with the merge commandDon't Commit Production Settings - Keep production
.env
files out of version controlDocument Your Setup - Document which configuration method and variable name your team uses
Verify Before Deployment - Always run this command to verify environment before deploying
Environment Precedence
Understanding precedence is important when multiple configurations exist:
.env file - WHEELS_ENV (highest priority)
↓
.env file - Environment
↓
System variable - WHEELS_ENV
↓
System variable - Environment
↓
Default: development (lowest priority)
If both WHEELS_ENV
and Environment
are set in .env
, only WHEELS_ENV
will be used.
Migration Guide
If you're migrating from a system that uses different environment variable names:
From "Environment" to "WHEELS_ENV"
# Old configuration
Environment=production
# New configuration (both work)
WHEELS_ENV=production
# The command will detect either one
wheels get environment
Gradual Migration
You can migrate gradually since the command checks both:
Leave existing
Environment
variables in placeStart using
WHEELS_ENV
for new deploymentsThe command will prefer
WHEELS_ENV
when both exist
Integration with Other Commands
This command works well with other Wheels CLI commands:
# Check environment, then run migrations
wheels get environment
wheels db migrate
# Verify environment before running tests
wheels get environment
wheels test
# Check environment, then start server
wheels get environment
commandbox server start
Tips
The command must be run from your Wheels application root directory
Environment values are case-sensitive (
development
≠Development
)Comments in
.env
files are properly ignored using#
Whitespace around values is automatically trimmed
The command clearly shows which variable name was found
WHEELS_ENV
takes precedence overEnvironment
when both exist
Troubleshooting
Environment Not Changing
If changing environment variables doesn't seem to work:
Run
wheels get environment
to see which source and variable is being usedRemember
.env
file takes precedence over system variablesRemember
WHEELS_ENV
takes precedence overEnvironment
Restart your CommandBox server after changes
Check for typos in variable names
Variable Priority Issues
If the wrong environment is being detected:
Check if both
WHEELS_ENV
andEnvironment
are setRemember
WHEELS_ENV
has higher priorityUse the output to see exactly which variable is being read
Permission Errors
If you get permission errors:
Ensure you have read access to
.env
filesCheck that you're in the correct directory
Verify file ownership and permissions
Unexpected Default
If you're getting the default development
when you expect a different value:
Check for typos in configuration files (it's
WHEELS_ENV
notWHEEL_ENV
)Ensure
.env
file is in the application rootVerify system environment variables are properly exported
Check that values don't have quotes unless intended
Last updated
Was this helpful?