Command Line Tools
Wheels get environment
Wheels get environment
Section titled “Wheels get environment”Overview
Section titled “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
Section titled “Command Syntax”wheels get environmentwheels get envParameters
Section titled “Parameters”This command takes no parameters.
Basic Usage
Section titled “Basic Usage”Display Current Environment
Section titled “Display Current Environment”wheels get environmentThis will output something like:
================================================== Current Environment: development==================================================
Configured in: Using default
To set an environment: - wheels env set environment_name - wheels env switch environment_name - Set WHEELS_ENV in .env fileHow It Works
Section titled “How It Works”Detection Priority
Section titled “Detection Priority”The command checks for environment configuration in the following order of precedence:
.envfile - Looks forWHEELS_ENVvariable first, thenEnvironmentvariable- System environment variable - Checks for
WHEELS_ENVfirst, thenEnvironmentsystem variable - Default - Falls back to
developmentif no configuration is found
The first valid configuration found is used and reported, along with which specific variable name was found.
Configuration Sources
Section titled “Configuration Sources”1. .env File
Section titled “1. .env File”The command first looks for a WHEELS_ENV variable in your application’s .env file:
# .env file - Primary variableWHEELS_ENV=productionDATABASE_HOST=localhostIf WHEELS_ENV is not found, it then checks for Environment:
# .env file - Alternative variableEnvironment=stagingDATABASE_HOST=localhostThe 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
Section titled “2. System Environment Variable”If not found in .env, it checks for system-level environment variables in the same order:
# Linux/Mac - Primary variableexport WHEELS_ENV=staging
# Windows - Primary variableset WHEELS_ENV=staging
# Or using the alternative variableexport Environment=production3. Default Value
Section titled “3. Default Value”If no configuration is found anywhere, it defaults to development.
Variable Priority
Section titled “Variable Priority”The command checks for two different variable names in this specific order:
WHEELS_ENVin.envfileEnvironmentin.envfileWHEELS_ENVsystem environment variableEnvironmentsystem environment variable- Default to
development
Output Examples
Section titled “Output Examples”Configured with WHEELS_ENV in .env
Section titled “Configured with WHEELS_ENV in .env”Current Environment:production
Configured in: .env file (WHEELS_ENV)Configured with Environment in .env
Section titled “Configured with Environment in .env”Current Environment:staging
Configured in: .env file (Environment)Configured via System Variable (WHEELS_ENV)
Section titled “Configured via System Variable (WHEELS_ENV)”Current Environment:staging
Configured in: System environment variable (WHEELS_ENV)Configured via System Variable (Environment)
Section titled “Configured via System Variable (Environment)”Current Environment:production
Configured in: System environment variable (Environment)Using Default
Section titled “Using Default”Current Environment:development
Configured in: Using defaultCommon Use Cases
Section titled “Common Use Cases”Verify Environment Before Deployment
Section titled “Verify Environment Before Deployment”# Check environment before starting serverwheels get environmentcommandbox server startTroubleshooting Configuration Issues
Section titled “Troubleshooting Configuration Issues”# Verify which configuration source and variable is being usedwheels get environment
# Check each source manuallycat .env | grep -E "WHEELS_ENV|Environment"echo $WHEELS_ENVecho $EnvironmentCI/CD Pipeline Verification
Section titled “CI/CD Pipeline Verification”# In deployment scriptwheels get environmentif [ $? -eq 0 ]; then echo "Environment configured successfully"fiSupporting Legacy Systems
Section titled “Supporting Legacy Systems”# If migrating from a system that uses "Environment" variable# Both will work without changes:# Old: Environment=production# New: WHEELS_ENV=productionwheels get environmentError Handling
Section titled “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
Section titled “Not a Wheels Application”Error: This command must be run from a Wheels application root directoryRead Error
Section titled “Read Error”Error reading environment: [specific error message]Best Practices
Section titled “Best Practices”-
Use WHEELS_ENV - Prefer
WHEELS_ENVoverEnvironmentfor clarity and consistency -
Consistent Configuration - Use one primary method for setting environment across your team
-
Environment-Specific Files - Consider using
.env.production,.env.developmentfiles with the merge command -
Don’t Commit Production Settings - Keep production
.envfiles out of version control -
Document 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
Section titled “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
Section titled “Migration Guide”If you’re migrating from a system that uses different environment variable names:
From “Environment” to “WHEELS_ENV”
Section titled “From “Environment” to “WHEELS_ENV””# Old configurationEnvironment=production
# New configuration (both work)WHEELS_ENV=production
# The command will detect either onewheels get environmentGradual Migration
Section titled “Gradual Migration”You can migrate gradually since the command checks both:
- Leave existing
Environmentvariables in place - Start using
WHEELS_ENVfor new deployments - The command will prefer
WHEELS_ENVwhen both exist
Integration with Other Commands
Section titled “Integration with Other Commands”This command works well with other Wheels CLI commands:
# Check environment, then run migrationswheels get environmentwheels db migrate
# Verify environment before running testswheels get environmentwheels test
# Check environment, then start serverwheels get environmentcommandbox server start- The command must be run from your Wheels application root directory
- Environment values are case-sensitive (
development≠Development) - Comments in
.envfiles are properly ignored using# - Whitespace around values is automatically trimmed
- The command clearly shows which variable name was found
WHEELS_ENVtakes precedence overEnvironmentwhen both exist
Troubleshooting
Section titled “Troubleshooting”Environment Not Changing
Section titled “Environment Not Changing”If changing environment variables doesn’t seem to work:
- Run
wheels get environmentto see which source and variable is being used - Remember
.envfile takes precedence over system variables - Remember
WHEELS_ENVtakes precedence overEnvironment - Restart your CommandBox server after changes
- Check for typos in variable names
Variable Priority Issues
Section titled “Variable Priority Issues”If the wrong environment is being detected:
- Check if both
WHEELS_ENVandEnvironmentare set - Remember
WHEELS_ENVhas higher priority - Use the output to see exactly which variable is being read
Permission Errors
Section titled “Permission Errors”If you get permission errors:
- Ensure you have read access to
.envfiles - Check that you’re in the correct directory
- Verify file ownership and permissions
Unexpected Default
Section titled “Unexpected Default”If you’re getting the default development when you expect a different value:
- Check for typos in configuration files (it’s
WHEELS_ENVnotWHEEL_ENV) - Ensure
.envfile is in the application root - Verify system environment variables are properly exported
- Check that values don’t have quotes unless intended