Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,11 @@ If you want to overwrite the `Version` variable in `main.go` you have add the fo
go build -o bin/cenv -ldflags "-X 'github.com/echo-webkom/cenv/cmd.Version=<your-version>'" app/main.go
```

## Man page

The `cenv` program also comes with a man page. Viewable by `man cenv`. You can install the man page locally with:

```bash
mkdir -p ~/.local/share/man/man1
cp cenv.1 ~/.local/share/man/man1
```
128 changes: 128 additions & 0 deletions cenv.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
.\" Manpage for cenv
.\" Contact support at github.com/echo-webkom/cenv for corrections or typos.
.TH CENV 1 "2025" "cenv" "User Commands"
.SH NAME
cenv \- validate and manage .env files using comment-based schemas
.SH SYNOPSIS
.B cenv
[\fICOMMAND\fR] [\fIOPTIONS\fR]
.SH DESCRIPTION
.B cenv
keeps your sanity in check by validating your .env files. It uses comments in .env files to generate a schema used for checking the env files integrity. When working on a larger project, env files can change a lot and sometimes break your app if you have forgotten to add/edit/update certain fields. With cenv you minimize this risk by having a source of truth that makes sure your env is set up correctly.
.SH COMMANDS
.TP
.B check
Check if .env matches schema
.TP
.B update
Generate schema based on .env
.TP
.B fix
Fix will create .env if one does not exist, fill in default/public values for empty fields, automatically fix issues with the .env if any, and always reuse values already in the .env
.TP
.B tags
Show list of available tags and their uses
.TP
.B help
Show help message
.TP
.B version
Show version
.TP
.B upgrade
Upgrade to latest version
.SH OPTIONS
.TP
.B \-\-env \fI<path>\fR
Path to env file, default is current directory
.TP
.B \-\-schema \fI<path>\fR
Path to schema file, default is current directory
.TP
.B \-\-skip\-version
Skip version check
.TP
.B \-\-version
Show version
.SH TAGS
The following tags can be added as comments above fields in your .env file:
.TP
.B @required
Field has to have a non-empty value
.TP
.B @public
Field is static and shown in schema. The value will be included in the schema. This is for required static values.
.TP
.B @default \fI<value>\fR
Field will be set to given default value if empty. Running 'cenv fix' will automatically fill this in if the field is empty.
.TP
.B @length \fI<n>\fR
Field must have given length
.TP
.B @format \fI<fmt>\fR
Field must have given format (gokenizer pattern). Uses gokenizer patterns from github.com/jesperkha/gokenizer
.TP
.B @enum \fI<values>\fR
Field must be one of the given values. Values are separated by a | character. Example: @enum user | admin | guest
.SH EXAMPLES
.TP
Example .env file with tags:
.nf
NOT_SO_IMPORTANT=123

# @required
API_KEY=foo-bar-baz

# @length 8
OTHER_KEY=abcdefgh

# Stacking multiple tags
# @required
# @length 4
# @format {number}
PIN_CODE=1234

# @enum user | guest | admin
# @default user
ROLE=user
.fi
.TP
Create a schema file from your .env:
.nf
cenv update
.fi
.TP
Check your .env after fetching the latest changes:
.nf
cenv check
.fi
.TP
Fix missing or incorrect values in .env:
.nf
cenv fix
.fi
.TP
Use custom paths:
.nf
cenv check --env /path/to/.env --schema /path/to/schema.json
.fi
.SH FILES
.TP
.I .env
Default environment file
.TP
.I cenv.schema.json
Default schema file generated by cenv
.SH INSTALLATION
Copy and run the following command. cenv will be put in $HOME/.local/bin. Make sure that the directory is in your $PATH.
.nf
curl -fsSL https://raw.githubusercontent.com/echo-webkom/cenv/refs/heads/main/install.sh | bash
.fi

Once installed, you can self-update with 'cenv upgrade'.
.SH BUGS
Report bugs at https://github.com/echo-webkom/cenv/issues
.SH AUTHOR
Written by the echo Webkom.
.SH SEE ALSO
env(1), bash(1)
12 changes: 12 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,17 @@ for bin in "${bins[@]}"; do
rm "$archive_path"
done

if [ "$OS" != "Windows_NT" ]; then
man_dir="$HOME/.local/share/man/man1"
mkdir -p "$man_dir"

man_url="https://raw.githubusercontent.com/$REPO/main/cenv.1"
curl --fail --location --silent --output "$man_dir/cenv.1" "$man_url"

if [ $? -ne 0 ]; then
echo "Warning: Failed to install man page"
fi
fi

echo "Installation completed successfully!"
echo "Run 'cenv --help' to get started"