Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/miniscruff/envexample
Generate a .env.example from an env struct
https://github.com/miniscruff/envexample
Last synced: 14 days ago
JSON representation
Generate a .env.example from an env struct
- Host: GitHub
- URL: https://github.com/miniscruff/envexample
- Owner: miniscruff
- License: mit
- Created: 2023-04-30T20:44:58.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-09T00:27:23.000Z (4 months ago)
- Last Synced: 2024-10-05T08:04:42.271Z (about 1 month ago)
- Language: Go
- Homepage:
- Size: 96.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# EnvExample
[![codecov](https://codecov.io/gh/miniscruff/envexample/branch/main/graph/badge.svg?token=7HT2E32FMB)](https://codecov.io/gh/miniscruff/envexample)
[![Go Report Card](https://goreportcard.com/badge/github.com/miniscruff/envexample)](https://goreportcard.com/report/github.com/miniscruff/envexample)
[![Release](https://img.shields.io/github/v/release/miniscruff/envexample?sort=semver)](https://github.com/miniscruff/envexample/releases)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/miniscruff/envexample/test.yml?branch=main)](https://github.com/miniscruff/envexample/actions?query=workflow%3Atest)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/miniscruff/envexample)](https://pkg.go.dev/github.com/miniscruff/envexample)Generate a `.env.example` from an [env labeled](https://github.com/caarlos0/env) struct
## Installation
The easiest way to install `envexample` is using `go install` from latest or by version.```sh
go install github.com/miniscruff/envexample@latest
go install github.com/miniscruff/[email protected]
```[All Installation Options](#all-installation-options) has the full list of options.
[CLI Arguments](./DOCS.md) has all the arguments.
## Usage
Given a configuration struct and using [env](https://github.com/caarlos0/env)
to parse environment variables like:```go
package mainimport (
"fmt""github.com/caarlos0/env/v9"
"github.com/joho/godotenv"
)// Config handles our applications configuration
type Config struct {
// Home is our users home directory
Home string `env:"HOME"`
// Port is our http listeners port address
Port int `env:"PORT" envDefault:"3000"`
// IsProduction is whether or not we are running in production
IsProduction bool `env:"PRODUCTION"`
}func main() {
// attempt to load .env file if found
_ = godotenv.Load()cfg := Config{}
if err := env.Parse(&cfg); err != nil {
fmt.Printf("%+v\n", err)
}fmt.Printf("%+v\n", cfg)
}
```You can run `envexample` like:
```sh
envexample -struct Config
```To generate an `.env.example` file similar to:
```sh
# Generated by envexample dev.# Config handles our applications configuration
#
# Home is our users home directory
#HOME=""
# IsProduction is whether or not we are running in production
#PRODUCTION=""
# Port is our http listeners port address
#PORT=3000
```This file should be commited to your source control, and a copy should be created
locally that is then loaded by your application.Something similar to `cp .env.example .env` would work.
## All Installation Options
### deb/rpm
Download a `.deb` or `.rpm` file from the [releases page](https://github.com/miniscruff/envexample/releases)
and install with `dpkg -i` and `rpm -i` respectively.### Windows Scoop
On windows you can use [scoop](https://scoop.sh/) by first adding the repo and then installing.
```sh
scoop bucket add envexample https://github.com/miniscruff/envexample
scoop install envexample
```### macOS with Homebrew
On macOS, you can use [Homebrew](https://brew.sh/) to install by first tapping
the repository.```sh
brew tap miniscruff/envexample https://github.com/miniscruff/envexample
brew install envexample
```### Manual
* Download from [here](https://github.com/miniscruff/envexample/releases).
* Add executable somewhere in your path depending on your platform.### From source
Go install can be used to download envexample from the main branch or by tag.```
go install github.com/miniscruff/envexample@latest
go install github.com/miniscruff/[email protected]
```## Tasks
Below is a list of common development tasks, these can easily be run using [xc](https://xcfile.dev/).
For example `xc test` will run the test suite.### test
Run unit test suite with code coverage enabled.
```
go test ./... -coverprofile=c.out
```### coverage
Run unit tests and preview the html coverage results.
requires: test
```
go tool cover -html=c.out
```### lint
```
goimports -w -local github.com/miniscruff/envexample .
golangci-lint run ./...
```### release
Run generation and prepare a release PR
requires: test,lint
```
go run main.go -h > DOCS.md
changie batch auto
changie merge
git checkout --branch release-$(changie latest)
gh pr create
```## License
Distributed under the [MIT License](LICENSE).