Skip to content

gonchihernandez/envMatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

envMatch πŸ¦€

Rust License: MIT GitHub

Environment Variable Manager - A powerful CLI tool written in Rust for managing environment variables across different environments (development, staging, production, etc.). Named in honor of Rust's elegant match statement for pattern matching environments.

✨ Features

  • πŸ”§ Multi-Environment Support - Manage separate variable sets for dev, staging, prod
  • 🎨 Beautiful TUI Interface - Interactive terminal user interface with Ratatui
  • πŸ”„ Easy Environment Switching - Switch between environments with a single command
  • βœ… Variable Validation - Ensure required variables are set before deployment
  • πŸ“‹ Smart Listing - View all variables in any environment
  • 🎯 Dual Interface - Both CLI commands and interactive TUI available
  • πŸ“ Local Storage - Variables stored securely in YAML files
  • πŸš€ Fast & Reliable - Built with Rust for performance and safety

πŸš€ Quick Start

Installation

From Source (Recommended)

# Clone the repository
git clone https://github.com/gonchihernandez/envMatch.git
cd envMatch

# Build the project
cargo build --release

# (Optional) Install globally
cargo install --path .

From crates.io (Coming Soon)

# Install from crates.io (when published)
cargo install envMatch

Manual Installation

# Download the latest release from GitHub
# Extract and run the binary directly
./envMatch --help

Basic Usage

Interactive TUI Mode (Default)

# Launch the interactive terminal interface (default when envMatch is initialized)
./envMatch
# or explicitly
./envMatch tui

The TUI provides a beautiful, interactive interface with:

  • πŸ“ Left Panel: Environment list with current environment highlighted
  • πŸ”§ Right Panel: Variable list for the selected environment
  • ⌨️ Keyboard Navigation:
    • Tab to switch between panels
    • ↑/↓ or k/j to navigate
    • a to add variables, e to edit, d to delete
    • Enter to switch environments
    • h or F1 for help
    • q to quit

Command Line Mode

# Initialize envMatch in your project
./envMatch init

# Set environment variables
./envMatch set DATABASE_URL postgres://localhost/myapp
./envMatch set API_KEY your_secret_key
./envMatch set DEBUG true

# Create production environment
./envMatch set DATABASE_URL postgres://prod-server/myapp --env production
./envMatch set API_KEY prod_secret_key --env production
./envMatch set DEBUG false --env production

# Switch environments
./envMatch switch production

# List current environment variables
./envMatch list

# Validate required variables
./envMatch validate --required DATABASE_URL,API_KEY

πŸ“š Commands

Interactive TUI

./envMatch tui
# or simply
./envMatch

Launches the interactive terminal user interface for visual management of environments and variables.

Initialize

./envMatch init

Creates .envMatch directory structure in your current project.

Set Variables

# Set in current environment (default: development)
./envMatch set KEY value

# Set in specific environment
./envMatch set KEY value --env production

Get Variables

# Get from current environment
./envMatch get KEY

# Get from specific environment
./envMatch get KEY --env production

Remove Variables

# Remove from current environment
cargo run -- unset KEY

# Remove from specific environment
cargo run -- unset KEY --env production

Environment Management

# Switch to different environment
cargo run -- switch production

# Show current environment
cargo run -- current

# List all available environments
cargo run -- envs

List Variables

# List variables in current environment
cargo run -- list

# List variables in specific environment
cargo run -- list --env production

Validation

# Check if required variables are set
cargo run -- validate --required DATABASE_URL,API_KEY

# General environment health check
cargo run -- validate

πŸ“ Project Structure

After initialization, envMatch creates:

your-project/
└── .envMatch/
    β”œβ”€β”€ config.yaml              # Global configuration
    └── environments/
        β”œβ”€β”€ development.yaml      # Development variables
        β”œβ”€β”€ production.yaml       # Production variables
        └── staging.yaml          # Staging variables (if created)

πŸ’‘ Example Workflow

# 1. Initialize in your project
cargo run -- init

# 2. Set up development environment
cargo run -- set DATABASE_URL postgres://localhost/myapp
cargo run -- set REDIS_URL redis://localhost:6379
cargo run -- set DEBUG true
cargo run -- set LOG_LEVEL debug

# 3. Set up production environment
cargo run -- set DATABASE_URL postgres://prod.example.com/myapp --env production
cargo run -- set REDIS_URL redis://prod.example.com:6379 --env production
cargo run -- set DEBUG false --env production
cargo run -- set LOG_LEVEL info --env production

# 4. Work in development
cargo run -- switch development
cargo run -- list
# Shows all dev variables

# 5. Deploy to production
cargo run -- switch production
cargo run -- validate --required DATABASE_URL,REDIS_URL
# βœ… All required variables are set in environment 'production'

# 6. Check what environments you have
cargo run -- envs
# πŸ“ Available environments:
# β€’ development
# β€’ production (current)

πŸ› οΈ Use Cases

For Developers

  • Local Development: Keep dev credentials separate from production
  • Testing: Create isolated test environments
  • Onboarding: New team members can quickly set up their environment

For DevOps

  • Deployment Validation: Ensure all required variables are set before deploy
  • Environment Parity: Keep track of what variables exist in each environment
  • Configuration Management: Centralized way to manage environment configs

For Teams

  • Consistency: Everyone uses the same variable names and structure
  • Documentation: Variables are clearly organized and discoverable
  • Security: Sensitive values aren't accidentally committed to git

πŸ”’ Security Notes

  • Variables are stored in local YAML files
  • The .envMatch directory should be added to .gitignore
  • For production use, consider additional encryption for sensitive values
  • Never commit the .envMatch directory to version control

οΏ½ Testing

Running Tests

# Run all tests (unit + integration)
cargo test

# Run only unit tests
cargo test --lib

# Run only integration tests
cargo test --test integration_tests

# Run tests with verbose output
cargo test -- --nocapture

Test Coverage

  • Unit Tests: 12 tests covering core functionality
  • Integration Tests: 13 tests covering CLI behavior
  • Architecture: Modular design with proper error handling
  • Test Coverage: All major features and edge cases

πŸ—οΈ Architecture

The project follows Rust best practices with a modular architecture:

src/
β”œβ”€β”€ main.rs           # CLI entry point and command routing
β”œβ”€β”€ commands/         # Business logic for each command
β”‚   └── mod.rs        # EnvMatchCommands implementation
β”œβ”€β”€ config/           # Configuration management
β”‚   └── mod.rs        # ConfigManager for file operations
└── error/            # Error handling
    └── mod.rs        # Custom error types with thiserror

tests/
└── integration_tests.rs  # End-to-end CLI testing

Key Design Principles

  • Separation of Concerns: Each module has a single responsibility
  • Error Handling: Comprehensive error types with helpful messages
  • Testability: Dependency injection for easy testing
  • Type Safety: Strong typing with custom Result types
  • Documentation: Extensive tests serve as documentation
  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/new-feature
  3. Make your changes
  4. Run tests: cargo test
  5. Commit changes: git commit -am 'Add new feature'
  6. Push to branch: git push origin feature/new-feature
  7. Submit a Pull Request

πŸ“‹ Requirements

  • Rust 1.70.0 or higher
  • Cargo (comes with Rust)

πŸ“¦ Dependencies

  • clap - Command-line argument parsing
  • serde - Serialization/deserialization
  • serde_yaml - YAML file handling

πŸ› Troubleshooting

"envMatch not initialized"

# Run this in your project directory
cargo run -- init

"Variable not found"

# Check what variables exist
cargo run -- list

# Check what environment you're in
cargo run -- current

"Failed to read environment file"

# The environment might not exist yet, create it by setting a variable
cargo run -- set EXAMPLE_VAR example_value --env your_environment

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Created by @gonchihernandez
  • Built with ❀️ using Rust
  • Inspired by Rust's powerful match statement for pattern matching
  • Thanks to the Rust community for amazing crates and tools

Made with πŸ¦€ Rust - Powered by match πŸ’ͺ
Original Author: @gonchihernandez

About

Environment Variable Manager - A CLI tool written in Rust for managing environment variables across different environments (development, staging, production, etc.). Named in honor of Rust's elegant match statement for pattern matching environments.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages