Skip to content

Commit ea1572f

Browse files
committed
Release of dotenvy 0.15.1
The following is also duplicated in the changelog. - `dotenv` crate forked as `dotenvy` - `dotenv_codegen` forked as `dotenvy_codgen` - `dotenv_codegen_implementation` forked as `dotenvy_codegen_impl` - Crate description for dotenvy_codegen - Crate description for dotenvy_codgen_impl - New language in README - MIT license badge in README - Generate helpful errors from dotenv! macro (full merge of [dotenv-rs/dotenv #58](https://github.com/dotenv-rs/dotenv/pull/57/files#)) - replaced deprecated `std::env_home:dir()` with `dirs:home_dir` - Better handling of `home_dir` (merge of [dotenv-rs/dotenv #62](https://github.com/dotenv-rs/dotenv/pull/62/files#)) - assertions dealing with `Result` (based on [dotenv-rs/dotenv #57](https://github.com/dotenv-rs/dotenv/pull/57/files#)) - upgraded clap in `dotenvy` bin from v2 to v3.1 (covers [dotenv-rs/dotenv #76](https://github.com/dotenv-rs/dotenv/pull/76/files)) - example folder. The simple example has been moved to the README. - `extern` - unnecessary `use` statements in doc examples
1 parent 3c1a77b commit ea1572f

27 files changed

+238
-284
lines changed

CHANGELOG.md

+35-7
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,64 @@
11
# Changelog
2+
23
All notable changes to this project will be documented in this file.
34

4-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6+
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [0.15.1] - 2022-02-28
9+
10+
### Added
11+
12+
- `dotenv` crate forked as `dotenvy`
13+
- `dotenv_codegen` forked as `dotenvy_codgen`
14+
- `dotenv_codegen_implementation` forked as `dotenvy_codegen_impl`
15+
- Crate description for dotenvy_codegen
16+
- Crate description for dotenvy_codgen_impl
17+
- New language in README
18+
- MIT license badge in README
19+
- Generate helpful errors from dotenv! macro (full merge of [dotenv-rs/dotenv #58](https://github.com/dotenv-rs/dotenv/pull/57/files#))
20+
21+
### Changed
22+
23+
- replaced deprecated `std::env_home:dir()` with `dirs:home_dir`
24+
- Better handling of `home_dir` (merge of [dotenv-rs/dotenv #62](https://github.com/dotenv-rs/dotenv/pull/62/files#))
25+
- assertions dealing with `Result` (based on [dotenv-rs/dotenv #57](https://github.com/dotenv-rs/dotenv/pull/57/files#))
26+
- upgraded clap in `dotenvy` bin from v2 to v3.1 (covers [dotenv-rs/dotenv #76](https://github.com/dotenv-rs/dotenv/pull/76/files))
627

7-
## [Unreleased]
28+
### Removed
29+
30+
- example folder. The simple example has been moved to the README.
31+
- `extern`
32+
- unnecessary `use` statements in doc examples
833

934
## [0.15.0] - 2019-10-21
1035

1136
### Changed
37+
1238
- Undeprecate `iter` methods
1339
- Library no longer has any dependencies
1440

1541
### Added
42+
1643
- Support for variables with a `.` in their name
1744
- Support `\n` in double-quoted lines
1845
- Support for variable substitution
1946

2047
## [0.14.1] - 2019-05-14
2148

2249
### Changed
50+
2351
- Deprecate `iter` methods.
2452

2553
## [0.14.0] - 2019-05-07
54+
2655
### Changed
56+
2757
- Switched repo to use cargo workspaces.
2858
- Renamed dotenv_codegen_impl to dotenv_codegen_implementation since we no longer own the original crate.
2959
- Update code to 2018 edition
3060

31-
32-
33-
[Unreleased]: https://github.com/dotenv-rs/dotenv/compare/v0.15.0...HEAD
61+
[unreleased]: https://github.com/dotenv-rs/dotenv/compare/v0.15.0...HEAD
3462
[0.15.0]: https://github.com/dotenv-rs/dotenv/compare/v0.14.1...v0.15.0
3563
[0.14.1]: https://github.com/dotenv-rs/dotenv/compare/v0.14.0...v0.14.1
36-
[0.14.0]: https://github.com/dotenv-rs/dotenv/compare/v0.13.0...v0.14.0
64+
[0.14.0]: https://github.com/dotenv-rs/dotenv/compare/v0.13.0...v0.14.0

Cargo.toml

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
[workspace]
22

3-
members = [
4-
"dotenv",
5-
"dotenv_codegen",
6-
"dotenv_codegen_implementation",
7-
]
3+
members = ["dotenv", "dotenv_codegen", "dotenv_codegen_impl"]

LICENSE.md renamed to LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21-
THE SOFTWARE.
21+
THE SOFTWARE.

README.md

+31-99
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,61 @@
1-
# rust-dotenv
1+
# dotenvy
22

3-
![CI](https://github.com/dotenv-rs/dotenv/workflows/CI/badge.svg)
4-
[![codecov](https://codecov.io/gh/dotenv-rs/dotenv/branch/master/graph/badge.svg)](https://codecov.io/gh/dotenv-rs/dotenv)
5-
[![Crates.io](https://img.shields.io/crates/v/dotenv.svg)](https://crates.io/crates/dotenv)
3+
[![crates.io](https://img.shields.io/crates/v/dotenvy.svg)](https://crates.io/crates/dotenv)
4+
![CI](https://github.com/allan2/dotenvy/workflows/CI/badge.svg)
5+
[![Released API docs](https://docs.rs/dotenvy/badge.svg)](https://docs.rs/dotenvy)
6+
[![codecov](https://codecov.io/gh/allan2/dotenvy/branch/master/graph/badge.svg)](https://codecov.io/gh/allan2/dotenvy)
67

7-
**Achtung!** This is a v0.\* version! Expect bugs and issues all around.
8-
Submitting pull requests and issues is highly encouraged!
8+
A well-maintained fork of the [dotenv](https://github.com/dotenv-rs/dotenv) crate.
99

10-
Quoting [bkeepers/dotenv][dotenv]:
10+
This library loads environment variables from a _.env_ file. This is convenient for dev environments.
1111

12-
> Storing [configuration in the environment](http://www.12factor.net/config)
13-
> is one of the tenets of a [twelve-factor app](http://www.12factor.net/).
14-
> Anything that is likely to change between deployment environments–such as
15-
> resource handles for databases or credentials for external services–should
16-
> be extracted from the code into environment variables.
12+
## Components
1713

18-
This library is meant to be used on development or testing environments in
19-
which setting environment variables is not practical. It loads environment
20-
variables from a `.env` file, if available, and mashes those with the actual
21-
environment variables provided by the operative system.
14+
1. `dotenvy` crate - A well-maintained fork of the `dotenv` crate.
15+
2. `dotenvy_codegen` crate - A macro for compile time dotenv inspection.
16+
3. `dotenvy_codgen_impl` crate - Internal implementation for dotenvy_codegen.
17+
4. `dotenvy` CLI tool for running a command using the environment from a _.env_ file (currently Unix only)
2218

23-
Usage
24-
----
19+
## Usage
2520

26-
The easiest and most common usage consists on calling `dotenv::dotenv` when the
27-
application starts, which will load environment variables from a file named
28-
`.env` in the current directory or any of its parents; after that, you can just call
29-
the environment-related method you need as provided by `std::os`.
21+
### Loading at runtime
3022

31-
If you need finer control about the name of the file or its location, you can
32-
use the `from_filename` and `from_path` methods provided by the crate.
33-
34-
`dotenv_codegen` provides the `dotenv!` macro, which
35-
behaves identically to `env!`, but first tries to load a `.env` file at compile
36-
time.
37-
38-
Examples
39-
----
40-
41-
A `.env` file looks like this:
42-
43-
```sh
44-
# a comment, will be ignored
45-
REDIS_ADDRESS=localhost:6379
46-
MEANING_OF_LIFE=42
47-
```
48-
49-
You can optionally prefix each line with the word `export`, which will
50-
conveniently allow you to source the whole file on your shell.
51-
52-
A sample project using Dotenv would look like this:
53-
54-
```rust
55-
extern crate dotenv;
56-
57-
use dotenv::dotenv;
23+
```rs
24+
use dotenvy::dotenv;
5825
use std::env;
5926

6027
fn main() {
6128
dotenv().ok();
6229

6330
for (key, value) in env::vars() {
64-
println!("{}: {}", key, value);
31+
println!("{key}: {value}");
6532
}
6633
}
6734
```
6835

69-
Variable substitution
70-
----
36+
### Loading at compile time
7137

72-
It's possible to reuse variables in the `.env` file using `$VARIABLE` syntax.
73-
The syntax and rules are similar to bash ones, here's the example:
38+
The `dotenv!` macro provided by `dotenvy_codegen` crate can be used.
7439

40+
Warning: there is an outstanding issue with rust-analyzer ([rust-analyzer #9606](https://github.com/rust-analyzer/rust-analyzer/issues/9606)) related to the `dotenv!` macro
7541

76-
```sh
42+
## Why does this fork exist?
7743

78-
VAR=one
79-
VAR_2=two
44+
The original dotenv crate has not been updated since June 26, 2020. Attempts to reach the authors and present maintainer were not successful ([dotenv-rs/dotenv #74](https://github.com/dotenv-rs/dotenv/issues/74)).
8045

81-
# Non-existing values are replaced with an empty string
82-
RESULT=$NOPE #value: '' (empty string)
46+
This fork is intended to serve as the development home for the dotenv implementation in Rust.
8347

84-
# All the letters after $ symbol are treated as the variable name to replace
85-
RESULT=$VAR #value: 'one'
48+
## What are the differences from the original?
8649

87-
# Double quotes do not affect the substitution
88-
RESULT="$VAR" #value: 'one'
50+
This repo fixes:
8951

90-
# Different syntax, same result
91-
RESULT=${VAR} #value: 'one'
52+
- home directory works correctly (no longer using the deprecated `std::env::home_dir`)
53+
- more helpful errors for `dotenv!` ([dotenv-rs/dotenv #57](https://github.com/dotenv-rs/dotenv/pull/57/files#))
9254

93-
# Curly braces are useful in cases when we need to use a variable with non-alphanumeric name
94-
RESULT=$VAR_2 #value: 'one_2' since $ with no curly braces stops after first non-alphanumeric symbol
95-
RESULT=${VAR_2} #value: 'two'
55+
For a full list of changes, read the [changelog](./CHANGELOG.md).
9656

97-
# The replacement can be escaped with either single quotes or a backslash:
98-
RESULT='$VAR' #value: '$VAR'
99-
RESULT=\$VAR #value: '$VAR'
100-
101-
# Environment variables are used in the substutution and always override the local variables
102-
RESULT=$PATH #value: the contents of the $PATH environment variable
103-
PATH="My local variable value"
104-
RESULT=$PATH #value: the contents of the $PATH environment variable, even though the local variable is defined
105-
```
57+
## Are you a usurper of the dotenv legacy?
10658

107-
Dotenv will parse the file, substituting the variables the way it's described in the comments.
108-
109-
110-
Using the `dotenv!` macro
111-
------------------------------------
112-
113-
Add `dotenv_codegen` to your dependencies, and add the following to the top of
114-
your crate:
115-
116-
```rust
117-
#[macro_use]
118-
extern crate dotenv_codegen;
119-
```
120-
121-
Then, in your crate:
122-
123-
```rust
124-
fn main() {
125-
println!("{}", dotenv!("MEANING_OF_LIFE"));
126-
}
127-
```
59+
Legend has it that the Lost Maintainer will return, merging changes from `dotenvy` into `dotenv` with such thrust that all `Cargo.toml`s will lose one keystroke. Only then shall the Rust dotenv crateverse be united in true harmony.
12860

129-
[dotenv]: https://github.com/bkeepers/dotenv
61+
Until then, this repo dutifully carries on the dotenv torch. It is actively maintained. Contributions and PRs are very welcome!

dotenv/Cargo.toml

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
2-
name = "dotenv"
3-
version = "0.15.0"
2+
name = "dotenvy"
3+
version = "0.15.1"
44
authors = [
55
"Noemi Lapresta <[email protected]>",
66
"Craig Hills <[email protected]>",
@@ -9,24 +9,26 @@ authors = [
99
"Sean Griffin <[email protected]>",
1010
"Adam Sharp <[email protected]>",
1111
"Arpad Borsos <[email protected]>",
12+
"Allan Zhang <[email protected]>",
1213
]
13-
description = "A `dotenv` implementation for Rust"
14-
homepage = "https://github.com/dotenv-rs/dotenv"
14+
description = "A well-maintained fork of the `dotenv` crate"
15+
homepage = "https://github.com/allan2/dotenvy"
1516
readme = "../README.md"
16-
keywords = ["environment", "env", "dotenv", "settings", "config"]
17+
keywords = ["dotenv", "env", "environment", "settings", "config"]
1718
license = "MIT"
18-
repository = "https://github.com/dotenv-rs/dotenv"
19+
repository = "https://github.com/allan2/dotenvy"
1920
edition = "2018"
2021

2122
[[bin]]
22-
name = "dotenv"
23+
name = "dotenvy"
2324
required-features = ["cli"]
2425

2526
[dependencies]
26-
clap = { version = "2", optional = true }
27+
clap = { version = "3.1", optional = true }
28+
dirs = "4.0"
2729

2830
[dev-dependencies]
29-
tempfile = "3.0.0"
31+
tempfile = "3.3.0"
3032

3133
[features]
3234
cli = ["clap"]

dotenv/examples/simple.rs

-10
This file was deleted.

dotenv/src/bin/dotenv.rs renamed to dotenv/src/bin/dotenvy.rs

+17-21
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
extern crate clap;
2-
extern crate dotenv;
3-
4-
use clap::{App, AppSettings, Arg};
1+
use clap::Arg;
52
use std::os::unix::process::CommandExt;
6-
use std::process::{exit, Command};
3+
use std::process;
74

85
macro_rules! die {
96
($fmt:expr) => ({
107
eprintln!($fmt);
11-
exit(1);
8+
process::exit(1);
129
});
1310
($fmt:expr, $($arg:tt)*) => ({
1411
eprintln!($fmt, $($arg)*);
15-
exit(1);
12+
process::exit(1);
1613
});
1714
}
1815

19-
fn make_command(name: &str, args: Vec<&str>) -> Command {
20-
let mut command = Command::new(name);
16+
fn make_command(name: &str, args: Vec<&str>) -> process::Command {
17+
let mut command = process::Command::new(name);
2118

2219
for arg in args {
2320
command.arg(arg);
@@ -27,42 +24,41 @@ fn make_command(name: &str, args: Vec<&str>) -> Command {
2724
}
2825

2926
fn main() {
30-
let matches = App::new("dotenv")
27+
let matches = clap::Command::new("dotenvy")
3128
.about("Run a command using the environment in a .env file")
32-
.usage("dotenv <COMMAND> [ARGS]...")
33-
.setting(AppSettings::AllowExternalSubcommands)
34-
.setting(AppSettings::ArgRequiredElseHelp)
35-
.setting(AppSettings::UnifiedHelpMessage)
29+
.override_usage("dotenvy <COMMAND> [ARGS]...")
30+
.allow_external_subcommands(true)
31+
.arg_required_else_help(true)
3632
.arg(
37-
Arg::with_name("FILE")
38-
.short("f")
33+
Arg::new("FILE")
34+
.short('f')
3935
.long("file")
4036
.takes_value(true)
4137
.help("Use a specific .env file (defaults to .env)"),
4238
)
4339
.get_matches();
4440

4541
match matches.value_of("FILE") {
46-
None => dotenv::dotenv(),
47-
Some(file) => dotenv::from_filename(file),
42+
None => dotenvy::dotenv(),
43+
Some(file) => dotenvy::from_filename(file),
4844
}
4945
.unwrap_or_else(|e| die!("error: failed to load environment: {}", e));
5046

5147
let mut command = match matches.subcommand() {
52-
(name, Some(matches)) => {
48+
Some((name, matches)) => {
5349
let args = matches
5450
.values_of("")
5551
.map(|v| v.collect())
5652
.unwrap_or(Vec::new());
5753

5854
make_command(name, args)
5955
}
60-
_ => die!("error: missing required argument <COMMAND>"),
56+
None => die!("error: missing required argument <COMMAND>"),
6157
};
6258

6359
if cfg!(target_os = "windows") {
6460
match command.spawn().and_then(|mut child| child.wait()) {
65-
Ok(status) => exit(status.code().unwrap_or(1)),
61+
Ok(status) => process::exit(status.code().unwrap_or(1)),
6662
Err(error) => die!("fatal: {}", error),
6763
};
6864
} else {

0 commit comments

Comments
 (0)