Command Line Tools
Wheels env validate
Wheels env validate
Section titled “Wheels env validate”Overview
Section titled “Overview”The wheels env validate command validates the format and content of .env files in your Wheels project. This command helps ensure your environment configuration is properly formatted, contains required variables, and follows best practices. It’s essential for catching configuration errors before deployment and maintaining consistent environment setups across different environments.
Command Syntax
Section titled “Command Syntax”wheels env validate [options]Options
Section titled “Options”| Option | Description | Default |
|---|---|---|
--file | Name of the .env file to validate | .env |
--required | Comma-separated list of required keys that must be present | empty |
--verbose | Show detailed validation information including all variables | false |
Basic Usage Examples
Section titled “Basic Usage Examples”Validate Default .env File
Section titled “Validate Default .env File”wheels env validateValidates the .env file in your project root
Validate Specific File
Section titled “Validate Specific File”wheels env validate --file=.env.productionValidates the .env.production file
Check Required Variables
Section titled “Check Required Variables”wheels env validate --required=DB_HOST,DB_USER,DB_PASSWORDValidates that specific required variables are present
Detailed Validation
Section titled “Detailed Validation”wheels env validate --verboseShows detailed information about all variables found
Advanced Usage Examples
Section titled “Advanced Usage Examples”Production Deployment Validation
Section titled “Production Deployment Validation”wheels env validate --file=.env.production --required=DB_HOST,DB_NAME,DB_USER,DB_PASSWORD,API_KEYEnsures production environment has all critical variables
Multi-Environment Validation
Section titled “Multi-Environment Validation”# Validate all environment fileswheels env validate --file=.env.developmentwheels env validate --file=.env.stagingwheels env validate --file=.env.productionRequired Variables by Environment
Section titled “Required Variables by Environment”# Development requirementswheels env validate --file=.env.development --required=DB_HOST,WHEELS_ENV
# Production requirementswheels env validate --file=.env.production --required=DB_HOST,DB_NAME,DB_USER,DB_PASSWORD,API_KEY,WHEELS_ENVComprehensive Validation
Section titled “Comprehensive Validation”wheels env validate --file=.env.production --required=DB_HOST,API_KEY --verboseCombines required variable checking with detailed output
Validation Checks
Section titled “Validation Checks”Format Validation
Section titled “Format Validation”The command validates several aspects of your .env file format:
1. File Format Detection
Section titled “1. File Format Detection”- Properties format: Standard
KEY=VALUEpairs - JSON format: Valid JSON structure
- Automatic detection based on content
2. Syntax Validation
Section titled “2. Syntax Validation”- Missing equals sign:
KEY VALUE(invalid) - Empty key names:
=value(invalid) - Valid key=value format:
KEY=value(valid)
3. Key Name Standards
Section titled “3. Key Name Standards”- Valid characters: Letters, numbers, underscores only
- Standard format:
UPPER_SNAKE_CASErecommended - Non-standard warnings: Mixed case, special characters
Content Validation
Section titled “Content Validation”1. Required Variables
Section titled “1. Required Variables”wheels env validate --required=DB_HOST,API_KEYEnsures specified variables are present and have values
2. Duplicate Key Detection
Section titled “2. Duplicate Key Detection”Identifies when the same key appears multiple times:
Line 15: Duplicate key: 'DB_HOST' (previous value will be overwritten)3. Placeholder Detection
Section titled “3. Placeholder Detection”Identifies common placeholder values in sensitive variables:
your_passwordyour_secretchange_mexxxTODO
Sample Output
Section titled “Sample Output”Successful Validation
Section titled “Successful Validation”================================================== Validating: .env==================================================
Summary--------------------------------------------------Total variables: 4
[SUCCESS]: Validation passed with no issues!Validation with Warnings
Section titled “Validation with Warnings”Validating: .env.development
Warnings: Line 5: Non-standard key name: 'dbHost' (should contain only letters, numbers, and underscores) Line 12: Placeholder value detected for 'API_KEY'
Summary: Total variables: 8
Validation passed with 2 warningsValidation with Errors
Section titled “Validation with Errors”================================================== Validating: .env==================================================
[FAILED]: Errors found: - Required key missing: 'DB_HOST' - Required key missing: 'API_KEY'
Summary--------------------------------------------------Total variables: 4
[FAILED]: Validation failed with 2 errorsVerbose Output
Section titled “Verbose Output”================================================== Validating: .env==================================================
Summary--------------------------------------------------Total variables: 4
Environment Variables:--------------------------------------------------
wheels: - wheels_env = development
DB: - DB_USER = root - DB_NAME = myapp - DB_PORT = 3306
API: - API_BASE_URL = https://api.example.com - API_KEY = ***MASKED*** - API_TIMEOUT = 30
Other: - APP_NAME = My Application - WHEELS_ENV = development
[SUCCESS]: Validation passed with no issues!Error Types and Solutions
Section titled “Error Types and Solutions”Format Errors
Section titled “Format Errors”Missing Equals Sign
Section titled “Missing Equals Sign”Error: Line 5: Invalid format (missing '='): DB_HOST localhostSolution: Add equals sign: DB_HOST=localhost
Empty Key Name
Section titled “Empty Key Name”Error: Line 8: Empty key nameSolution: Provide a key name: MY_KEY=value
Invalid JSON
Section titled “Invalid JSON”Error: Invalid JSON format: Unexpected character at position 15Solution: Fix JSON syntax or convert to properties format
Content Errors
Section titled “Content Errors”Required Key Missing
Section titled “Required Key Missing”Error: Required key missing: 'API_KEY'Solution: Add the missing variable: API_KEY=your-api-key
Empty Required Value
Section titled “Empty Required Value”Warning: Required key has empty value: 'DB_PASSWORD'Solution: Provide a value: DB_PASSWORD=your-password
Warning Types
Section titled “Warning Types”Non-Standard Key Name
Section titled “Non-Standard Key Name”Warning: Line 3: Non-standard key name: 'dbHost' (should contain only letters, numbers, and underscores)Recommendation: Use DB_HOST instead of dbHost
Placeholder Value
Section titled “Placeholder Value”Warning: Line 7: Placeholder value detected for 'API_KEY'Recommendation: Replace placeholder with actual value
Duplicate Key
Section titled “Duplicate Key”Warning: Line 12: Duplicate key: 'DB_PORT' (previous value will be overwritten)Recommendation: Remove duplicate or rename one key
Common Use Cases
Section titled “Common Use Cases”Pre-Deployment Validation
Section titled “Pre-Deployment Validation”# Validate production config before deploymentwheels env validate --file=.env.production --required=DB_HOST,DB_NAME,DB_USER,DB_PASSWORD,API_KEY
# Check staging environmentwheels env validate --file=.env.staging --required=DB_HOST,API_KEYDevelopment Workflow
Section titled “Development Workflow”# Quick validation during developmentwheels env validate
# Detailed check when debuggingwheels env validate --verboseCI/CD Integration
Section titled “CI/CD Integration”# In your deployment pipelinewheels env validate --file=.env.production --required=DB_HOST,API_KEYif [ $? -ne 0 ]; then echo "Environment validation failed!" exit 1fiEnvironment Setup Verification
Section titled “Environment Setup Verification”# Validate new team member's setupwheels env validate --required=DB_HOST,WHEELS_ENV,API_KEY
# Check if all environments are properly configuredfor env in development staging production; do wheels env validate --file=.env.$envdoneConfiguration Auditing
Section titled “Configuration Auditing”# Regular audit of all environment fileswheels env validate --file=.env.development --verbosewheels env validate --file=.env.production --verboseBest Practices
Section titled “Best Practices”1. Regular Validation
Section titled “1. Regular Validation”# Add to your development routinewheels env validate2. Environment-Specific Requirements
Section titled “2. Environment-Specific Requirements”# Define different requirements for different environmentswheels env validate --file=.env.development --required=DB_HOST,WHEELS_ENVwheels env validate --file=.env.production --required=DB_HOST,DB_NAME,DB_USER,DB_PASSWORD,API_KEY3. Pre-Commit Validation
Section titled “3. Pre-Commit Validation”# Add to git pre-commit hooks#!/bin/shwheels env validate --file=.env.example4. Deployment Pipeline Integration
Section titled “4. Deployment Pipeline Integration”# In CI/CD pipelinewheels env validate --file=.env.production --required=DB_HOST,API_KEY5. Use Verbose Mode for Documentation
Section titled “5. Use Verbose Mode for Documentation”# Generate configuration documentationwheels env validate --verbose > config-validation-report.txtIntegration with Other Commands
Section titled “Integration with Other Commands”With Environment Setup
Section titled “With Environment Setup”# Set variables then validatewheels env set DB_HOST=localhost DB_PORT=3306wheels env validate --required=DB_HOST,DB_PORTWith File Merging
Section titled “With File Merging”# Merge files then validate resultwheels env merge .env.base .env.local --output=.env.mergedwheels env validate --file=.env.merged --required=DB_HOST,API_KEYWith Configuration Display
Section titled “With Configuration Display”# Validate then show configurationwheels env validate --verbosewheels env showExit Codes
Section titled “Exit Codes”The command returns different exit codes for automation:
- 0: Validation passed (may have warnings)
- 1: Validation failed (has errors)
This makes it perfect for use in scripts and CI/CD pipelines:
if wheels env validate --file=.env.production; then echo "Production config is valid" # Continue with deploymentelse echo "Production config has errors" exit 1fiTips and Recommendations
Section titled “Tips and Recommendations”Security Best Practices
Section titled “Security Best Practices”- Use the validation to catch placeholder values in sensitive variables
- Regularly validate that required security-related variables are present
- Use
--verbosemode carefully in CI/CD (sensitive values are masked but logs might be visible)
Development Workflow
Section titled “Development Workflow”- Validate environment files before committing changes
- Use different required variable lists for different environments
- Set up validation as part of your local development setup script
Team Collaboration
Section titled “Team Collaboration”- Include validation in project setup documentation
- Use validation to ensure consistent environment setup across team members
- Define standard required variables for your project type
Automation
Section titled “Automation”- Integrate validation into deployment pipelines
- Use exit codes to fail deployments when validation errors occur
- Set up regular validation checks for configuration drift detection