Command Line Tools
Wheels env merge
Wheels env merge
Section titled “Wheels env merge”Overview
Section titled “Overview”The wheels env merge command allows you to merge multiple environment configuration files (.env files) into a single consolidated file. This is particularly useful when working with different environments (development, staging, production) or when you have base configurations that need to be combined with environment-specific overrides.
Command Syntax
Section titled “Command Syntax”wheels env merge <source1> <source2> [source3...] [options]Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
| source1 | string | Yes | First source .env file to merge |
| source2 | string | Yes | Second source .env file to merge |
| source3, source4, … | string | No | Additional source .env files to merge (unlimited) |
| —output | string | No | Output file name (default: .env.merge) |
| —dryRun | flag | No | Show what would be merged without actually writing the file |
Basic Usage Examples
Section titled “Basic Usage Examples”Simple Two-File Merge
Section titled “Simple Two-File Merge”wheels env merge .env.defaults .env.localThis merges .env.defaults and .env.local into .env.merge
Custom Output File
Section titled “Custom Output File”wheels env merge .env.defaults .env.local --output=.envThis merges the files and saves the result as .env
Production Environment Merge
Section titled “Production Environment Merge”wheels env merge source1=.env source2=.env.production --output=.env.mergedCombines base configuration with production-specific settings
Multiple File Merge
Section titled “Multiple File Merge”wheels env merge source1=base.env source2=common.env source3=dev.env source4=local.env --output=.env.developmentMerges multiple files in the specified order (unlimited number of source files supported)
Dry Run (Preview)
Section titled “Dry Run (Preview)”wheels env merge base.env override.env --dryRunShows what the merged result would look like without creating a file
How It Works
Section titled “How It Works”File Processing Order
Section titled “File Processing Order”Files are processed in the order they are specified on the command line. Later files take precedence over earlier ones when there are conflicting variable names.
Supported File Formats
Section titled “Supported File Formats”- Properties format (standard .env format):
DATABASE_HOST=localhostDATABASE_PORT=5432API_KEY=your-secret-key
- JSON format:
{"DATABASE_HOST": "localhost","DATABASE_PORT": "5432","API_KEY": "your-secret-key"}
File Parsing Details
Section titled “File Parsing Details”- Empty lines and comments (lines starting with
#) are skipped in properties files - Values can contain
=signs (everything after the first=is considered the value) - Leading and trailing whitespace is trimmed from keys and values
- The command automatically detects whether a file is JSON or properties format
Conflict Resolution
Section titled “Conflict Resolution”When the same variable exists in multiple files:
- The value from the last processed file wins
- Conflicts are tracked and reported with details showing:
- The variable name
- The original value and source file
- The new value and source file
- You’ll see a summary showing which values were overridden
Output Features
Section titled “Output Features”Organized Structure
Section titled “Organized Structure”The merged output file is automatically organized:
- Variables are grouped by prefix (e.g.,
DATABASE_*,API_*) - Groups are sorted alphabetically
- Variables within groups are sorted alphabetically
- Includes generated header comments with:
- Generation timestamp
- Source information
- Section headers for each variable group
Security Features
Section titled “Security Features”When using --dryRun or viewing output, sensitive values are automatically masked:
- Variables containing
password,secret,key, ortoken(case-insensitive) show as***MASKED*** - The actual values are still written to the output file (only display is masked)
- Each variable shows its source file for traceability
Common Use Cases
Section titled “Common Use Cases”Development Workflow
Section titled “Development Workflow”# Start with base configurationwheels env merge source1=.env.base source2=.env.development --output=.env
# Add local overrideswheels env merge source1=.env source2=.env.local --output=.envMulti-Environment Setup
Section titled “Multi-Environment Setup”# Merge base, environment, and local configswheels env merge source1=.env.base source2=.env.staging source3=.env.local --output=.envDeployment Preparation
Section titled “Deployment Preparation”# Create production configurationwheels env merge source1=.env.base source2=.env.production --output=.env.prod
# Preview staging configurationwheels env merge source1=.env.base source2=.env.staging --dryRunConfiguration Validation
Section titled “Configuration Validation”# Check what the final configuration looks likewheels env merge source1=.env.defaults source2=.env.current --dryRunSample Output
Section titled “Sample Output”Command Execution
Section titled “Command Execution”Merging environment files: 1. .env.defaults 2. .env.local 3. .env.override
Merged 3 files into .env.merge Total variables: 15
Conflicts resolved (later files take precedence): DATABASE_HOST: 'db.example.com' (.env.defaults) → 'localhost' (.env.local) DEBUG_MODE: 'false' (.env.defaults) → 'true' (.env.override)Dry Run Output
Section titled “Dry Run Output”Merged result (DRY RUN):
DATABASE Variables: DATABASE_HOST = localhost (from .env.local) DATABASE_NAME = myapp (from .env.defaults) DATABASE_PASSWORD = ***MASKED*** (from .env.local) DATABASE_PORT = 5432 (from .env.defaults)
API Variables: API_BASE_URL = https://api.example.com (from .env.defaults) API_KEY = ***MASKED*** (from .env.local) API_TOKEN = ***MASKED*** (from .env.override)
Other Variables: APP_NAME = MyApplication (from .env.defaults) DEBUG_MODE = true (from .env.override)Generated File Format
Section titled “Generated File Format”# Merged Environment Configuration# Generated by wheels env merge command# Date: 2024-12-15 14:30:45
# API ConfigurationAPI_BASE_URL=https://api.example.comAPI_KEY=actual-key-valueAPI_TOKEN=actual-token-value
# DATABASE ConfigurationDATABASE_HOST=localhostDATABASE_NAME=myappDATABASE_PASSWORD=actual-passwordDATABASE_PORT=5432
# Other ConfigurationAPP_NAME=MyApplicationDEBUG_MODE=trueError Handling
Section titled “Error Handling”The command will stop and show an error if:
- Source files don’t exist
- Less than two source files are provided
- Output file cannot be written (permissions, disk space, etc.)
- File read operations fail
Important Notes
Section titled “Important Notes”- Default output filename is
.env.merge(not.env.merged) - Multiple files supported - You can merge any number of files (not just 2 or 3)
- Option format - Use double dashes for options:
--output,--dryRun - Value preservation - Values containing
=signs are properly preserved - Comment handling - Comments in source files are not preserved in the merged output
Best Practices
Section titled “Best Practices”-
Use descriptive file names that indicate their purpose (
.env.base,.env.production,.env.local) -
Order files by precedence - place base/default files first, overrides last
-
Use dry-run first to preview results before committing to a merge
-
Keep sensitive data in local files that aren’t committed to version control
-
Document your merge strategy in your project’s README
-
Backup important configurations before merging
-
Review conflicts - Pay attention to the conflicts report to ensure expected overrides
- The merged file includes helpful comments showing when it was generated
- Variables are automatically organized by prefix for better readability
- Use the
--dryRunoption to understand what changes will be made - The command validates all source files exist before starting the merge process
- You can merge as many files as needed in a single command
- The source file information is preserved during dry runs for debugging