loadenv

command module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2022 License: MIT Imports: 8 Imported by: 0

README

loadenv

Loads environment files before running a command without polluting your environment

Source code

You can find the source code here: git.milar.in

Installation

If you have Go installed, you can simply go install the program: go install git.milar.in/milarin/loadenv@latest

There are pre-compiled executables for various platforms on the repository.

License

Distributed under the MIT License. See LICENSE.md

Usage

loadenv loads the environment file provided via -f into the environment and runs the command provided after the arguments. If no file is provided, .env is used by default. If no command is provided, loadenv prints all environment variables to stdout.


The variables will only be available to the given command. They will be deleted after the command exits. loadenv can be useful when working with programs which heavily use environment variables.

$ cat .env
# production server configuration
DATABASE_HOST=prod-server.com
DATABASE_USER=milarin
DATABASE_PASS=my-super-secure-password

$ # show the 3 last added env variables
$ loadenv | tail -n 3
DATABASE_HOST=prod-server.com
DATABASE_USER=milarin
DATABASE_PASS=my-super-secure-password

$ cat dev.env
# development server configuration
DATABASE_HOST=dev-server.com
DATABASE_USER=milarin
DATABASE_PASS=my-super-secure-password

$ # load dev.env into environment and run the command env. show last 3 lines
$ loadenv -f dev.env env | tail -n 3
DATABASE_HOST=dev-server.com
DATABASE_USER=milarin
DATABASE_PASS=my-super-secure-password

environment variables in that file will be expanded:

$ env | grep USER # current value of $USER
USER=milarin

$ cat .env
# expand $USER reference
USERNAME=$USER

$ loadenv | tail -n 1
USERNAME=milarin

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL