env2file
is a command-line tool that extracts environment variable keys from .env
files and stores them in a separate file. This helps developers easily identify which environment variables an application depends on.
The tool also provides an option to automatically commit the extracted keys to a Git repository.
- Extracts environment variable keys from
.env
files. - Stores the keys in a separate file (e.g.,
.env.example
). - Supports automatic Git integration to commit the extracted keys.
- Built as a native executable using GraalVM for better performance.
- Command-line interface powered by PicoCLI.
- Java 17 or later (for running the JAR file).
- GraalVM (if using the compiled binary version).
- Git (if using the Git integration feature).
java -jar env2file.jar <path_to_env_file> [output_file]
Make the binary executable and move it to /usr/local/bin
for global access:
chmod +x env2file
sudo mv env2file /usr/local/bin/
Now you can run:
env2file <path_to_env_file> [output_file]
env2file /path/to/.env .env.example
This will extract all environment variable keys from the .env
file and store them in .env.example
.
env2file /path/to/repo --git
This will:
- Extract environment keys from
.env
files. - Store them in
.env.example
. - Commit the changes to the Git repository with the message:
chore: add environment keys to sample file
To automate the execution of env2file
every time you run git push
, create a Git pre-push hook:
- Navigate to your Git repository:
cd /path/to/your/repo
- Create a new pre-push hook:
nano .git/hooks/pre-push
- Add the following script to execute
env2file
before pushing:#!/bin/bash env2file --git /path/to/repoo
- Save the file and give it executable permissions:
chmod +x .git/hooks/pre-push
Now, every time you run git push
, the tool will extract the environment keys, update .env.example
, and commit the changes automatically.
env2file --help
$ env2file .env .env.example
Wrote 10 environment keys to .env.example
Feel free to open issues or submit pull requests if you have improvements or suggestions.