https://github.com/shirajshrestha/env_reader
A gem to manage env variables easily. Find and validate the variables easily
https://github.com/shirajshrestha/env_reader
gem rails ruby
Last synced: over 1 year ago
JSON representation
A gem to manage env variables easily. Find and validate the variables easily
- Host: GitHub
- URL: https://github.com/shirajshrestha/env_reader
- Owner: ShirajShrestha
- Created: 2024-12-09T07:36:18.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-10T17:17:34.000Z (over 1 year ago)
- Last Synced: 2025-02-07T10:15:50.418Z (over 1 year ago)
- Topics: gem, rails, ruby
- Language: Ruby
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# EnvReader
The EnvReader gem is a utility to manage and validate environment variables used in your project. It helps in reading, finding and validating the environment variables used in your project.
## Installation
Add the gem to your `Gemfile`:
```Gemfile
gem 'env_reader'
```
Run `bundle install`
```bash
bundle install
```
OR
You can directly add it using `bundle add`
```bash
bundle add env_reader
```
## Usage
The gem offers several features through its Command-Line Interface (CLI). You can use the commands listed below to find, read, and validate environment keys.
- ### CLI Commands
Run the script using one of the following options:
| Command | Description |
| ----------------------------- | ------------------------------------------------------- |
| `-r, --read-keys [DIRECTORY]` | List all the environment keys used in a directory. |
| `-f, --find-keys [DIRECTORY]` | Find all files and display their environment key usage. |
| `-v, --validate-keys` | Validate environment keys and check for missing values. |
| `-e, --extensions x,y,z` | Specify file extensions to scan (default: rb, erb). |
| `-h, --help` | Display help for the available commands. |
### Directly using in a rails directory
1. **Without passing directory and extensions**
- List all the env variables used in the app
```bash
env_reader -r
```
- Find the files where the variables are used
```
env_reader -f
```
- Check if the env variables are set or missing and shows if valid or not
```
env_reader -v
```
2. **By passing directory and extension**
```bash
env_reader -f /path/to/directory -e rb, erb
```
You can exclude either one or both directory or extension if not necessary. Additionally you can also use other commands to read, find and validate the keys.
3. **Optional Keys**
Some keys are optional and may not need validation (e.g., CI, RAILS_ENV). You can modify the list of optional keys in the `optional_keys` method:
To add custom optional keys during validation:
```
env_reader -v --optional-keys MY_CUSTOM_KEY,ANOTHER_KEY
```
4. **Help Menu**
Run the `-h` or `--help` option to see the available commands.
```
env_reader -h
```
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/ShirajShrestha/env_reader