This document covers the environment management system in Tushell CLI, which allows users to switch between different configurations using environment files.
The Tushell CLI supports loading environment variables from different .env files using the --env parameter. This enables users to manage multiple configurations and switch between them easily without modifying their system environment variables.
When running Tushell commands, environment variables are loaded in the following sequence:
.env file in the current directory (if it exists)$HOME/.env (if it exists)--env parameter (if provided)Each step can override variables set in the previous steps, with the --env parameter having the highest priority.
The environment loading is implemented in the main cli() function in tushellcli.py:
@click.group()
@click.option('--env', '-E', default=None, help='Path to an alternative environment file to load')
def cli(env):
"""Main CLI group with optional environment file loading."""
if env:
# Load environment variables from the specified file
if os.path.exists(env):
load_dotenv(env, override=True) # Use override=True to ensure variables are updated
# Store the environment file path as an environment variable
os.environ["TUSHELL_ENV_FILE"] = env
click.echo(f"Loaded environment variables from {env}")
else:
click.echo(f"Error: Environment file {env} not found.")
sys.exit(1)
The following environment variables are particularly important for Tushell functionality:
| Variable | Description |
|---|---|
EH_API_URL |
The API URL for communicating with the Echo Horizon service |
EH_TOKEN |
Authentication token for API calls |
EH_ENV_NAME |
Optional name for the environment (displayed in command output) |
TUSHELL_ENV_FILE |
Set automatically when --env is used to track which file was loaded |
To use a specific environment file:
tushell --env /path/to/your/file.env command [options]
For example:
tushell --env .env.production scan-keys --pattern "*resonance*"
Environment files follow the standard .env format:
# Example .env.production file
EH_API_URL=https://production-api.example.com
EH_TOKEN=your_production_token
EH_ENV_NAME=Production
Commands like scan-keys display which environment they’re using. The display name is determined in this order of precedence:
EH_ENV_NAME if setTUSHELL_ENV_FILE if the --env parameter was usedFor example:
$ tushell --env .env.production scan-keys
Loaded environment variables from .env.production
🔑 Scanning keys using Production environment 🔑
You can view information about the current environment with the --debug flag:
$ tushell --env .env.production scan-keys --debug
This will display:
EH_ENV_NAME if setTUSHELL_ENV_FILE if set.env.purpose naming pattern (e.g., .env.development, .env.staging, .env.production).env files containing sensitive tokens to version control.env.example file with placeholder values to document required variablesEH_ENV_NAME to a descriptive name for each environment to make it clear which one is activeAll commands in Tushell that interact with external services (like scan-keys, get-memory, etc.) are environment-aware. They fetch the environment variables at runtime rather than caching them at module level, ensuring they always use the most recently loaded values.
This design ensures that when you switch environments with --env, all commands will correctly use the new environment settings.
If you encounter issues with environment variables not being recognized:
--debug flag to see which variables are being loaded= sign)--env override those in the system environmentscan-keys command that uses these environment settings