Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cuongnb14/format-env
Format env is a Go command-line utility to generate and format environment files (.env) using a template
https://github.com/cuongnb14/format-env
Last synced: 1 day ago
JSON representation
Format env is a Go command-line utility to generate and format environment files (.env) using a template
- Host: GitHub
- URL: https://github.com/cuongnb14/format-env
- Owner: cuongnb14
- Created: 2024-09-13T09:09:01.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-09-14T08:29:46.000Z (2 months ago)
- Last Synced: 2024-09-15T00:34:22.297Z (2 months ago)
- Language: Go
- Homepage:
- Size: 1.78 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Format env
format-env is a Go command-line utility to generate and format environment files (.env) using a template. This tool allows you to specify the environment (e.g., dev, testing, staging, etc.) and a template file to generate the corresponding environment configuration file.# Features
- Reads key-value pairs from an existing .env file.
- Applies the values to a template for formatting.
- Supports multiple stages (dev, testing, unstable, staging).
- Allows specifying the template path and stage dynamically through command-line arguments.# Installation
## Option 1: Donwload binary file
```sh
# for macos arm64
wget https://github.com/cuongnb14/format-env/releases/download/v1.0.1/fenv_darwin_arm64 -O fenv
sudo mv fenv /usr/local/bin/
sudo chmod +x /usr/local/bin/fenv
```## Option 2: Compile from source
To build and install the utility, make sure you have Go installed, and then run:
```
go build -o fenv fenv.go
```Move the binary to your $PATH for easy access:
```
sudo mv fenv /usr/local/bin/
sudo chmod +x /usr/local/bin/fenv
```
# UsageTo use the utility, run it from the command line by specifying the template file and the environment stage you want to generate.
```
fenv
```
- env_dir: Path to the env dir (e.g., `env/`). The template file name `_template.env` must have in this folder
- stages: The environment stage, separate by comma (e.g. `dev,testing,staging`).Example
```
| env
|--- _template.env
|--- dev.env
|--- staging.env
|--- prod.env# run format
fenv env/ dev,staging,prod
```
# Template Syntax
The template file should use Go’s text/template syntax. For example:
```
# General
# =======================================================================
STAGE={{ .STAGE }}
PORT={{ df .PORT "8000" }}# Database
# =======================================================================
DB_HOST={{ .DB_HOST }}
DB_PORT={{ .DB_PORT }}
DB_USER={{ .DB_USER }}
DB_PASS={{ .DB_PASS }}
DB_NAME={{ df .DB_NAME "example" }}# Redis
# =======================================================================
REDIS_ENABLE_SSL={{ df .REDIS_ENABLE_SSL "false" }}
REDIS_URL={{ .REDIS_URL }}
```
Note: This template will render the environment variable `REDIS_ENABLE_SSL` and use a default value `false` if it is not provided.