Skip to main content

dotenvx命令行总览

这里我们讨论的dotenvx命令行,是指dotenvx Rust命令行,地址为: https://github.com/linux-china/dotenvx-rs

Dotenvx命令行是我们操作.env文件的主要方式,让我们看一下标准的帮助信息:

dotenvx - encrypts your .env files, limiting their attack vector while retaining their benefits.

Usage: dotenvx [OPTIONS] [COMMAND]

Commands:
init Create a .env file with a new public/private key pair
run Inject env at runtime [dotenvx run -- your-command]
get return a single environment variable
set set a single environment variable
encrypt convert .env file(s) to encrypted .env file(s)
decrypt convert encrypted .env file(s) to plain .env file(s)
verify Verify the signature of the encrypted .env file
keypair Validate and print public/private keys for .env file in current directory
ls print all .env files in a tree structure
rotate rotate keypair and re-encrypt .env file in current directory
diff Display keys' values between all .env files
cloud Dotenv cloud operations, such as registration, sync, audit etc.
help Print this message or the help of the given subcommand(s)

Options:
-p, --profile <profile> Profile to use (such as 'dev', 'test', 'stage', 'prod', etc.)
-c, --command <command>... Run the command with injected environment variables from .env file
--seal Seal the $HOME/.env.keys file with AES256 encryption and your password
--unseal Unseal the $HOME/.env.keys.aes file with AES256 decryption and your password
--no-color Disable colored output, and you can use NO_COLOR env variable too.
-h, --help Print help
-V, --version Print version

有同学可能有疑问,为何不使用编辑器直接编辑.env文件呢?提供功能完备的命令行工具,意义大吗? 考虑到目前程序员的编辑器基本上都具备AI能力,也就是你在编辑任何文件时,可能你的代码就已经去云上转了一圈,然后获得对应的AI建议。

功能完备的命令行行工具,可以方便我们更安全地管理和使用.env文件,特别是对于加密和解密操作,当然命令行也方便自动化, 如dotenvx就提供了GitHub Actions的集成