Skip to content

u-yas/ennbu

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

ennbu

ennbu logo

.env utility CLI

ennbu is a command-line interface (CLI) tool for managing .env files in your projects, written in Go. It allows you to easily set, replace, list, and get values of keys within your .env files.

Features

  • Get a specific key-value pair from a .env file
  • List all key-value pairs in a .env file
  • Set a new value for a key in a .env file, creating the key if it doesn't exist
  • Replace a value for an existing key in a .env file

Installation

There are several ways to install ennbu:

  1. Using Go To install ennbu with Go, make sure you have Go installed on your system, and then run:
go install github.com/u-yas/ennbu@latest
  1. Downloading from GitHub Releases
curl -L -o ennbu https://github.com/u-yas/ennbu/releases/download/v0.0.1/ennbu-linux-x86_64.tar.gz
sudo mv ennbu /usr/local/bin/
  1. Using Docker
docker run -it -v "$(pwd):/workdir" ghcr.io/u-yas/ennbu:latest <command>
  1. Github Action
---
name: "golang testing"
on:
  pull_request:
    branches:
      - main
jobs:
  build:
    timeout-minutes: 15
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-go@v4
        with:
          go-version-file: "./go.mod"
      - name: go mod download
        run: go mod download
      - name: replace APP_ENV
        uses: u-yas/ennbu@v0.0.4
        with:
          envPath: .env
          commands: |
            set -k APP_ENV test
            list --json
      - name: go test
        run: go test ./...

Usage

Get

To get the value of a specific key in a .env file, use the get command:

ennbu get KEY_NAME -f .env

--unescape or -u

# .env
KEY_NAME="aa\nbbb\n\tccc"
# normally
ennbu get KEY_NAME
# aa\nbbb\nccc

# unescape
ennbu get KEY_NAME -u
#aa
#bb
#cc

List

To list all key-value pairs in a .env file, use the list command:

ennbu list -f .env

To list the key-value pairs in JSON format, use the --json flag:

ennbu list --json -f .env

ennbu list --json output

Set

To set a new value for a key in a .env file, use the set command:

ennbu set -f .env -k KEY_NAME VALUE

Replace

To replace a value for an existing key in a .env file, use the replace command:

echo NEW_VALUE | ennbu replace  -f .env -k KEY_NAME

--escape flags escape value

ennbu set -k A "aaa
bbb

cc"
A="aaa\nbbb\n\ncc"

--importFile flags enabled, read content from args

ennbu set -k PRIVATE_KEY --importFile ~/.ssh/id_ed25519 --escape
PRIVATE_KEY="-----BEGIN OPENSSH PRIVATE KEY-----\\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\\n-----END OPENSSH PRIVATE KEY-----"

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue.