EonaCat.EnvTool
1.0.0
Prefix Reserved
dotnet add package EonaCat.EnvTool --version 1.0.0
NuGet\Install-Package EonaCat.EnvTool -Version 1.0.0
<PackageReference Include="EonaCat.EnvTool" Version="1.0.0" />
<PackageVersion Include="EonaCat.EnvTool" Version="1.0.0" />
<PackageReference Include="EonaCat.EnvTool" />
paket add EonaCat.EnvTool --version 1.0.0
#r "nuget: EonaCat.EnvTool, 1.0.0"
#:package EonaCat.EnvTool@1.0.0
#addin nuget:?package=EonaCat.EnvTool&version=1.0.0
#tool nuget:?package=EonaCat.EnvTool&version=1.0.0
EonaCat.EnvTool
Cross-platform environment variable manager for:
- Windows
- Linux
- Docker / Docker Compose
EnvTool provides a unified CLI and API for managing:
- Process environment variables
- User environment variables
- Machine-wide environment variables
- Docker Compose
.envfiles
It also supports:
- Docker container restart automation
.envbackups- Atomic writes
- Variable expansion
- Raw output mode
- Custom
.envlocations
Build
dotnet build
Publish
Windows
dotnet publish -c Release -r win-x64 --self-contained true
Linux
dotnet publish -c Release -r linux-x64 --self-contained true
Usage
General Syntax
envtool <command> <scope> <key> [value] [options]
Examples
Process Variables
Set
envtool set process API_KEY abc123
Get
envtool get process API_KEY
Delete
envtool delete process API_KEY
User Variables
Set
envtool set user API_KEY abc123
Get
envtool get user API_KEY
Delete
envtool delete user API_KEY
Machine Variables
Set
envtool set machine API_KEY abc123
Linux machine variables may require:
sudo envtool set machine API_KEY abc123
Docker Support
EnvTool can manage Docker Compose .env files.
Example:
DB_PASSWORD=supersecret
Used by:
env_file: ./.env
and:
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
Docker Examples
Set Docker Variable
envtool set docker DB_PASSWORD supersecret
Get Docker Variable
envtool get docker DB_PASSWORD
Delete Docker Variable
envtool delete docker DB_PASSWORD
Docker Options
Custom .env File
envtool set docker DB_PASSWORD secret --file ./docker/.env
Restart Containers Automatically
envtool set docker DB_PASSWORD secret --restart
Equivalent to:
docker compose up -d
after updating the .env.
Raw Output Mode
Useful for scripts.
envtool get docker DB_PASSWORD --raw
Output:
supersecret
instead of JSON.
JSON Output
Default output format:
{
"success": true,
"value": "supersecret",
"error": null
}
Docker Compose Example
services:
db:
env_file: ./.env
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
Then:
envtool set docker DB_PASSWORD mypassword
updates .env automatically.
File Backups
Before changing .env, EnvTool creates:
.env.bak
Atomic Writes
EnvTool uses temporary files and atomic replacement to avoid corruption during writes.
Variable Expansion
Supported:
API_URL=${HOST}/api
EnvTool resolves ${HOST} using system environment variables.
Linux Shell Detection
EnvTool automatically detects:
.bashrc.zshrc.profile
depending on the active shell.
API Usage
Set Variable
await EnvironmentManager.SetAsync(
"DB_PASSWORD",
"secret",
EnvScope.Docker);
Get Variable
var result =
await EnvironmentManager.GetAsync(
"DB_PASSWORD",
EnvScope.Docker);
Delete Variable
await EnvironmentManager.DeleteAsync(
"DB_PASSWORD",
EnvScope.Docker);
Error Handling
All operations return:
EnvResult
Example:
{
"success": false,
"error": "Invalid environment variable key"
}
Security Notes
- Machine-level Linux writes may require
sudo .envfiles can contain secrets- Use proper filesystem permissions
- Avoid committing
.envfiles to source control
Recommended:
.env
.env.*
Recommended Docker Setup
Example:
services:
configurator:
env_file:
- ./.env
environment:
ConnectionStrings__DefaultConnection:
Host=db;
Port=5432;
Database=configurator;
Username=postgres;
Password=${DB_PASSWORD}
Then manage secrets with:
envtool set docker DB_PASSWORD supersecret --restart
Program example:
using EonaCat.EnvTool;
using EonaCat.EnvTool.Models;
using EonaCat.Json;
if (args.Length < 3)
{
Console.WriteLine("""
Usage:
envtool get <scope> <key>
envtool set <scope> <key> <value>
envtool delete <scope> <key>
Scopes:
process
user
machine
docker
Options:
--file <path>
--restart
--raw
""");
return;
}
var command = args[0].ToLowerInvariant();
var scope = ParseScope(args[1]);
var key = args[2];
bool raw = args.Contains("--raw");
string? file = GetOption("--file");
bool restart = args.Contains("--restart");
var dockerOptions = new DockerOptions
{
EnvFilePath = file ?? Path.Combine(Directory.GetCurrentDirectory(), ".env"),
RestartContainers = restart
};
EnvResult result;
switch (command)
{
case "get":
result = await EnvironmentManager.GetAsync(key, scope, dockerOptions);
break;
case "set":
if (args.Length < 4)
{
Console.WriteLine("Missing value");
return;
}
result = await EnvironmentManager.SetAsync(key, args[3], scope, dockerOptions);
break;
case "delete":
result = await EnvironmentManager.DeleteAsync(key, scope, dockerOptions);
break;
default:
Console.WriteLine("Unknown command");
return;
}
if (raw)
{
Console.WriteLine(result.Value);
}
else
{
Console.WriteLine(JsonHelper.ToJson(result));
}
return;
static EnvScope ParseScope(string scope)
{
return scope
.ToLowerInvariant() switch
{
"process" => EnvScope.Process,
"user" => EnvScope.User,
"machine" => EnvScope.Machine,
"docker" => EnvScope.Docker,
_ => EnvScope.Process
};
}
string? GetOption(string name)
{
var index = Array.IndexOf(args, name);
if (index < 0)
{
return null;
}
if (index + 1 >= args.Length)
{
return null;
}
return args[index + 1];
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- EonaCat.Json (>= 2.2.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 93 | 5/12/2026 |