TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: Envelope – A modern environment variable cli tool

103 点作者 mattrighetti11 个月前
Hey HN! I&#x27;ve built this cli tool to manage env variables of a project, but mostly for fun and to try out Rust and the clap crate.<p>I had this idea when I made a big mistake and broke some production stuff because I had a very messy .env file laying around in my project.<p>I was implementing new features for one of my projects and in my .env file I had the test database url commented out and the production one was not. Long story short, I applied migrations to the production database instead of my local test one and broke a lot of production APIs :&#x27;)<p>I wanted a tool that could easily help me spot these issues before something bad happened, and so I built envelope for that reason.<p>Instead of a \.env(\..+)? file, I now use this tool to add variables to different configurations: dev, prod etc. and I feed them to the program I am executing on a one liner.<p><pre><code> $ envelope init $ envelope add dev db_url localhost:5432&#x2F;postgres $ envelope add dev db_username username $ envelope add dev db_pwd pwd $ export $(envelope list dev) $ .&#x2F;run.sh </code></pre> This way I am explicitly exporting the dev environment without relying on the fact that everything is in order in my .env file (another approach would be to have a .env.dev file)<p>A very useful feature that I use quite a lot is the `check` command which is going to tell you which environment you have currently active<p><pre><code> $ export $(envelope list dev) $ envelope check &gt; dev </code></pre> I don&#x27;t think this tool is going to be useful to anybody, but I wanted to share this with you in case there is someone that can make good use of it or find particular scenarios where this could be used instead of .env files, either way I had a lot of fun building it

14 条评论

leetrout11 个月前
A word of caution - this is a way to leak your secrets through your shell history:<p><pre><code> $ envelope add dev db_pwd pwd </code></pre> There are settings such that a command that starts with a space will not be saved in the history which would help here but I would be very careful about how you use this.
评论 #40760221 未加载
评论 #40776999 未加载
bloopernova11 个月前
Interesting!<p>Have you looked at mise-en-place at all? It&#x27;s written in rust too, and might have some cool ideas to use: <a href="https:&#x2F;&#x2F;mise.jdx.dev&#x2F;" rel="nofollow">https:&#x2F;&#x2F;mise.jdx.dev&#x2F;</a>
breck11 个月前
I like it.<p>Env variables should be a solved problem but no one has made the simplest general solution yet. Seems like you are on track.<p>One suggestion: no need to use SQLite. Just develop a simple (and _lasting_), plain text DSL and save to a file.<p>Here&#x27;s one I made using your example.<p><a href="https:&#x2F;&#x2F;sdk.scroll.pub&#x2F;designer&#x2F;#parsers%0A%20valueCell%0A%20%20highlightScope%20string%0A%20variableNameCell%0A%20%20highlightScope%20keyword%0A%20%0A%20envelopeParser%0A%20%20root%0A%20%20description%20This%20is%20a%20stub%20for%20a%20DSL%20for%20Mattia%20Righetti&#x27;%20Envelope%20tool.%0A%20%20catchAllParser%20catchAllErrorParser%0A%20%20inScope%20variableParser%0A%20variableParser%0A%20%20catchAllCellType%20valueCell%0A%20%20cells%20variableNameCell%0A%20%20pattern%20%5BA-Z_%5D%2B%0A%20catchAllErrorParser%0A%20%20baseParser%20errorParser%0Asample%0A%20API_KEY%20your_api_key_here%0A%20AWS_ACCESS_KEY_ID%20your_access_key_id%0A%20DATABASE_URL%20postgres%3A%2F%2Fuser%3Apassword%40localhost%3A5432%2Fmydb%0A%20DEBUG_MODE%20true%0A%20SECRET_KEY%20mysecretkey123%0A%20SMTP_HOST%20smtp.example.com" rel="nofollow">https:&#x2F;&#x2F;sdk.scroll.pub&#x2F;designer&#x2F;#parsers%0A%20valueCell%0A%2...</a><p>I&#x27;m happy to chat more to nail that design if that would be helpful.
评论 #40760332 未加载
评论 #40761607 未加载
评论 #40759944 未加载
评论 #40759902 未加载
tomwphillips11 个月前
Of all the adjectives to use, why “modern”?<p>Very common these days. I don’t get it.
评论 #40761616 未加载
评论 #40761158 未加载
评论 #40761712 未加载
评论 #40760667 未加载
评论 #40760337 未加载
评论 #40777167 未加载
评论 #40761318 未加载
Kwpolska11 个月前
The docs don’t make it very obvious how are the environment variables actually applied. And I think .env files are much easier to manage and share. `envelope check` could be replaced with a CURRENT_ENV environment variable in an .env file. I can’t see how it would help avoid environment confusion more than $CURRENT_ENV displayed in your prompt would. (Or even better, not having production credentials on developers’ machines…)
评论 #40762297 未加载
globular-toast11 个月前
Seems neat, but direnv can do more despite this claiming to be &quot;modern&quot;.
another-dave11 个月前
&gt; This way I am explicitly exporting the dev environment without relying on the fact that everything is in order in my .env file (another approach would be to have a .env.dev file)<p>What did you find lacking with the .env.dev approach? (Or if some tool doesn&#x27;t support .env.dev could always symlink .env → .env.dev)
评论 #40762247 未加载
stephenr11 个月前
&gt; I had the test database url commented out and the production one was not.<p>I feel like this is a giant red flag. Why on earth is your production database accessible from anywhere (ie your PC) without some kind of extra layer of security like a VPN or SSH tunnel?
评论 #40762330 未加载
skeledrew11 个月前
Hmm I fairly recently started saving variables which tend to be shared among multiple projects in a central location, grouped in sh files and sourcing as needed. This gives me an idea to improve that flow...
applgo44311 个月前
When i deploy a webapp on azure, it expects me to put env variables in a file or their own tool (key value fields) where you can add env variables one by one.<p>Is there a way to use envelope in places like those?
SeriousM11 个月前
envkey.com is also distributing environment variables
nodesocket11 个月前
Any plans to support encryption at rest?
cranberryturkey11 个月前
how do I install the damn thing??
评论 #40758787 未加载
twerkmonsta11 个月前
you probably don’t need sql
评论 #40762359 未加载