lem

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 13 Imported by: 0

README

lem logo

The local env manager

The env splitting, delivery, replacement, and monitoring tool for monorepo

CI Go Report Card LICENSE LATEST Ask DeepWiki

Overview

LEM stands for Local Env Manager, and its logo is inspired by Lemmings. This tool is designed for monorepos where back-end APIs, front-end UIs, infrastructure resources, and more are managed together. It provides utilities to centrally manage .env files and distribute them to separate directory roots according to your configuration. The basic concept is to use prefixes for environment variable management, while also supporting unprefixed variables for flexible delivery.

Features

This tool supports the following features:

  • Generate a template for the configuration file
  • Validate configuration with fine granularity
  • Switch stages and persist the current stage
  • Split, replace prefixes, and distribute the central .env to each directory
  • Monitor the central .env and reflect changes automatically
  • Detect empty environment variable values and exit with an error
  • Automatically generate .envrc and use watch_file for direnv integration

Commands

NAME:
   lem - The local env manager for monorepo

USAGE:
   lem [global options] [command [command options]]

VERSION:
   0.0.0 (revision: XXXXXXX)

COMMANDS:
   init      Initialize the configuration file to current directory
   validate  Validate that the configuration file is executable
   stage     Show the current stage context
   switch    Toggle the current stage to the specified stage
   list      Show the env file entries in the current stage
   run       Switch env and deliver env files to the specified directory
   watch     Watch changes in the central env and run continuously

GLOBAL OPTIONS:
   --help, -h     show help
   --version, -v  print the version

Configuration

Set up with TOML format as follows:

[stage]
default = "<central-env-dir>/.env"
dev = "<central-env-dir>/.env.development"
stg = "<central-env-dir>/.env.staging"
prod = "<central-env-dir>/.env.production"

[group.api]
prefix = "API"
dir = "./backend"
replace = ["REPLACEABLE1"]
plain = ["PLAIN1"]
check = true
direnv = ["api", "ui"]

[group.ui]
prefix = "UI"
dir = "./frontend"
replace = ["REPLACEABLE2"]
plain = ["PLAIN2"]
check = true
direnv = ["ui"]

[!NOTE] The path must be either relative to the configuration file location or absolute.

Table Key Value Description
stage <string> string The pairs of stage name and .env file path. If not specified, default is used.
group.<id> prefix string The prefixes environment variables to be delivered by the group.
group.<id> dir string The destination for the group to be delivered.
group.<id> replace array<string> The Prefixes of the environment variable to be delivered after being replaced by the prefix defined by the group.
group.<id> plain array<string> The environment variables to be delivered without prefixes.
group.<id> check bool Whether the group performs an empty value check or not.
group.<id> direnv array<id> Automatically generate .envrc in each directory, write watch_file to track changes.

Installation

Install with homebrew

brew install nekrassov01/tap/lem

Install with go

go install github.com/nekrassov01/lem@latest

Or download binary from releases

Shell completion

Supported Shells are as follows:

  • bash
  • zsh
  • fish
  • pwsh
lem completion bash|zsh|fish|pwsh

# In the case of bash
source <(lem completion bash)

Todo

  • Support direnv Integration
  • Logging

Author

nekrassov01

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init() error

Init initializes the configuration file with an example. You can use this to create a new configuration file.

func Version added in v0.1.0

func Version() string

Version returns the version and revision.

Types

type Config

type Config struct {
	Stage map[string]string `toml:"stage"` // Stage holds the path to the central environment file.
	Group map[string]Group  `toml:"group"` // Group holds the configuration for each group of environment variables.
	// contains filtered or unexported fields
}

Config holds settings such as where the central env is located, how it is divided, and to which groups it is delivered. It is read from a configuration file in TOML format.

func Load

func Load(path string, opts ...Option) (*Config, error)

Load loads and instantiates the specified configuration file path.

func (*Config) Current added in v0.0.6

func (cfg *Config) Current() error

Current shows the current stage context.

func (*Config) List added in v0.0.6

func (cfg *Config) List() ([]Entry, error)

List returns a slice of Entry for all env entries of all groups for the given stage. If stage is empty, returns an error.

func (*Config) Run

func (cfg *Config) Run() (string, error)

Run reads the central environment and divides and distributes it to each group based on the configuration file. If necessary, it also checks if the environment variable values are empty.

func (*Config) Switch added in v0.0.6

func (cfg *Config) Switch(stage string) error

Switch switches the current stage to the specified one.

func (*Config) Validate

func (cfg *Config) Validate() error

Validate verifies that the configuration file is executable. In addition to syntax checks, it also checks whether the path exists.

func (*Config) Watch

func (cfg *Config) Watch() (string, error)

Watch watches for changes in the env file for the specified stage and executes the run command when a change is detected. Monitoring continues as long as it is not interrupted.

type Entry added in v0.0.6

type Entry struct {
	Group  string // Group is the group name of the environment variable
	Prefix string // Prefix is the prefix for the environment variable names of its group
	Type   string // Type indicates whether the env entry is indirect
	Name   string // Name is the key of the env entry, used for identification
	Value  string // Value is the value of the env entry
}

Entry represents an environment variable entry.

type Group

type Group struct {
	Prefix        string   `toml:"prefix"`  // Prefix for the environment variable names
	Dir           string   `toml:"dir"`     // Directory to which the environment variables are delivered
	Replaceable   []string `toml:"replace"` // List of prefixes to be delivered by replacing group prefixes
	Plain         []string `toml:"plain"`   // List of environment variables delivered without prefixes
	DirenvSupport []string `toml:"direnv"`  // Groups for which .envrc is generated
	IsCheck       bool     `toml:"check"`   // Whether to check for empty values
}

Group groups environment variables using several parameters.

type Option

type Option func(*Config)

Option is an option given when loading the configuration file.

func WithSize

func WithSize(size int) Option

WithSize sets the size to be allocated when reading the central env into the map. If not used, this value remains 32.

func WithWriter

func WithWriter(w io.Writer) Option

WithWriter sets the specified writer to the Config. If not used, the output remains standard output.

Directories

Path Synopsis
cmd
lem command

Jump to

Keyboard shortcuts

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