-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
27 changed files
with
238 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,64 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). | ||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [0.15.1] - 2022-02-28 | ||
|
||
### Added | ||
|
||
- `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#)) | ||
|
||
### Changed | ||
|
||
- 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)) | ||
|
||
## [Unreleased] | ||
### Removed | ||
|
||
- example folder. The simple example has been moved to the README. | ||
- `extern` | ||
- unnecessary `use` statements in doc examples | ||
|
||
## [0.15.0] - 2019-10-21 | ||
|
||
### Changed | ||
|
||
- Undeprecate `iter` methods | ||
- Library no longer has any dependencies | ||
|
||
### Added | ||
|
||
- Support for variables with a `.` in their name | ||
- Support `\n` in double-quoted lines | ||
- Support for variable substitution | ||
|
||
## [0.14.1] - 2019-05-14 | ||
|
||
### Changed | ||
|
||
- Deprecate `iter` methods. | ||
|
||
## [0.14.0] - 2019-05-07 | ||
|
||
### Changed | ||
|
||
- Switched repo to use cargo workspaces. | ||
- Renamed dotenv_codegen_impl to dotenv_codegen_implementation since we no longer own the original crate. | ||
- Update code to 2018 edition | ||
|
||
|
||
|
||
[Unreleased]: https://github.com/dotenv-rs/dotenv/compare/v0.15.0...HEAD | ||
[unreleased]: https://github.com/dotenv-rs/dotenv/compare/v0.15.0...HEAD | ||
[0.15.0]: https://github.com/dotenv-rs/dotenv/compare/v0.14.1...v0.15.0 | ||
[0.14.1]: https://github.com/dotenv-rs/dotenv/compare/v0.14.0...v0.14.1 | ||
[0.14.0]: https://github.com/dotenv-rs/dotenv/compare/v0.13.0...v0.14.0 | ||
[0.14.0]: https://github.com/dotenv-rs/dotenv/compare/v0.13.0...v0.14.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
[workspace] | ||
|
||
members = [ | ||
"dotenv", | ||
"dotenv_codegen", | ||
"dotenv_codegen_implementation", | ||
] | ||
members = ["dotenv", "dotenv_codegen", "dotenv_codegen_impl"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,129 +1,61 @@ | ||
# rust-dotenv | ||
# dotenvy | ||
|
||
![CI](https://github.com/dotenv-rs/dotenv/workflows/CI/badge.svg) | ||
[![codecov](https://codecov.io/gh/dotenv-rs/dotenv/branch/master/graph/badge.svg)](https://codecov.io/gh/dotenv-rs/dotenv) | ||
[![Crates.io](https://img.shields.io/crates/v/dotenv.svg)](https://crates.io/crates/dotenv) | ||
[![crates.io](https://img.shields.io/crates/v/dotenvy.svg)](https://crates.io/crates/dotenv) | ||
![CI](https://github.com/allan2/dotenvy/workflows/CI/badge.svg) | ||
[![Released API docs](https://docs.rs/dotenvy/badge.svg)](https://docs.rs/dotenvy) | ||
[![codecov](https://codecov.io/gh/allan2/dotenvy/branch/master/graph/badge.svg)](https://codecov.io/gh/allan2/dotenvy) | ||
|
||
**Achtung!** This is a v0.\* version! Expect bugs and issues all around. | ||
Submitting pull requests and issues is highly encouraged! | ||
A well-maintained fork of the [dotenv](https://github.com/dotenv-rs/dotenv) crate. | ||
|
||
Quoting [bkeepers/dotenv][dotenv]: | ||
This library loads environment variables from a _.env_ file. This is convenient for dev environments. | ||
|
||
> Storing [configuration in the environment](http://www.12factor.net/config) | ||
> is one of the tenets of a [twelve-factor app](http://www.12factor.net/). | ||
> Anything that is likely to change between deployment environments–such as | ||
> resource handles for databases or credentials for external services–should | ||
> be extracted from the code into environment variables. | ||
## Components | ||
|
||
This library is meant to be used on development or testing environments in | ||
which setting environment variables is not practical. It loads environment | ||
variables from a `.env` file, if available, and mashes those with the actual | ||
environment variables provided by the operative system. | ||
1. `dotenvy` crate - A well-maintained fork of the `dotenv` crate. | ||
2. `dotenvy_codegen` crate - A macro for compile time dotenv inspection. | ||
3. `dotenvy_codgen_impl` crate - Internal implementation for dotenvy_codegen. | ||
4. `dotenvy` CLI tool for running a command using the environment from a _.env_ file (currently Unix only) | ||
|
||
Usage | ||
---- | ||
## Usage | ||
|
||
The easiest and most common usage consists on calling `dotenv::dotenv` when the | ||
application starts, which will load environment variables from a file named | ||
`.env` in the current directory or any of its parents; after that, you can just call | ||
the environment-related method you need as provided by `std::os`. | ||
### Loading at runtime | ||
|
||
If you need finer control about the name of the file or its location, you can | ||
use the `from_filename` and `from_path` methods provided by the crate. | ||
|
||
`dotenv_codegen` provides the `dotenv!` macro, which | ||
behaves identically to `env!`, but first tries to load a `.env` file at compile | ||
time. | ||
|
||
Examples | ||
---- | ||
|
||
A `.env` file looks like this: | ||
|
||
```sh | ||
# a comment, will be ignored | ||
REDIS_ADDRESS=localhost:6379 | ||
MEANING_OF_LIFE=42 | ||
``` | ||
|
||
You can optionally prefix each line with the word `export`, which will | ||
conveniently allow you to source the whole file on your shell. | ||
|
||
A sample project using Dotenv would look like this: | ||
|
||
```rust | ||
extern crate dotenv; | ||
|
||
use dotenv::dotenv; | ||
```rs | ||
use dotenvy::dotenv; | ||
use std::env; | ||
|
||
fn main() { | ||
dotenv().ok(); | ||
|
||
for (key, value) in env::vars() { | ||
println!("{}: {}", key, value); | ||
println!("{key}: {value}"); | ||
} | ||
} | ||
``` | ||
|
||
Variable substitution | ||
---- | ||
### Loading at compile time | ||
|
||
It's possible to reuse variables in the `.env` file using `$VARIABLE` syntax. | ||
The syntax and rules are similar to bash ones, here's the example: | ||
The `dotenv!` macro provided by `dotenvy_codegen` crate can be used. | ||
|
||
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 | ||
|
||
```sh | ||
## Why does this fork exist? | ||
|
||
VAR=one | ||
VAR_2=two | ||
This comment has been minimized.
Sorry, something went wrong. |
||
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)). | ||
|
||
# Non-existing values are replaced with an empty string | ||
RESULT=$NOPE #value: '' (empty string) | ||
This fork is intended to serve as the development home for the dotenv implementation in Rust. | ||
|
||
# All the letters after $ symbol are treated as the variable name to replace | ||
RESULT=$VAR #value: 'one' | ||
## What are the differences from the original? | ||
|
||
# Double quotes do not affect the substitution | ||
RESULT="$VAR" #value: 'one' | ||
This repo fixes: | ||
|
||
# Different syntax, same result | ||
RESULT=${VAR} #value: 'one' | ||
- home directory works correctly (no longer using the deprecated `std::env::home_dir`) | ||
- more helpful errors for `dotenv!` ([dotenv-rs/dotenv #57](https://github.com/dotenv-rs/dotenv/pull/57/files#)) | ||
|
||
# Curly braces are useful in cases when we need to use a variable with non-alphanumeric name | ||
RESULT=$VAR_2 #value: 'one_2' since $ with no curly braces stops after first non-alphanumeric symbol | ||
RESULT=${VAR_2} #value: 'two' | ||
For a full list of changes, read the [changelog](./CHANGELOG.md). | ||
|
||
# The replacement can be escaped with either single quotes or a backslash: | ||
RESULT='$VAR' #value: '$VAR' | ||
RESULT=\$VAR #value: '$VAR' | ||
|
||
# Environment variables are used in the substutution and always override the local variables | ||
RESULT=$PATH #value: the contents of the $PATH environment variable | ||
PATH="My local variable value" | ||
RESULT=$PATH #value: the contents of the $PATH environment variable, even though the local variable is defined | ||
``` | ||
## Are you a usurper of the dotenv legacy? | ||
|
||
Dotenv will parse the file, substituting the variables the way it's described in the comments. | ||
|
||
|
||
Using the `dotenv!` macro | ||
------------------------------------ | ||
|
||
Add `dotenv_codegen` to your dependencies, and add the following to the top of | ||
your crate: | ||
|
||
```rust | ||
#[macro_use] | ||
extern crate dotenv_codegen; | ||
``` | ||
|
||
Then, in your crate: | ||
|
||
```rust | ||
fn main() { | ||
println!("{}", dotenv!("MEANING_OF_LIFE")); | ||
} | ||
``` | ||
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. | ||
|
||
[dotenv]: https://github.com/bkeepers/dotenv | ||
Until then, this repo dutifully carries on the dotenv torch. It is actively maintained. Contributions and PRs are very welcome! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "dotenv" | ||
version = "0.15.0" | ||
name = "dotenvy" | ||
version = "0.15.1" | ||
authors = [ | ||
"Noemi Lapresta <[email protected]>", | ||
"Craig Hills <[email protected]>", | ||
|
@@ -9,24 +9,26 @@ authors = [ | |
"Sean Griffin <[email protected]>", | ||
"Adam Sharp <[email protected]>", | ||
"Arpad Borsos <[email protected]>", | ||
"Allan Zhang <[email protected]>", | ||
] | ||
description = "A `dotenv` implementation for Rust" | ||
homepage = "https://github.com/dotenv-rs/dotenv" | ||
description = "A well-maintained fork of the `dotenv` crate" | ||
homepage = "https://github.com/allan2/dotenvy" | ||
readme = "../README.md" | ||
keywords = ["environment", "env", "dotenv", "settings", "config"] | ||
keywords = ["dotenv", "env", "environment", "settings", "config"] | ||
license = "MIT" | ||
repository = "https://github.com/dotenv-rs/dotenv" | ||
repository = "https://github.com/allan2/dotenvy" | ||
edition = "2018" | ||
|
||
[[bin]] | ||
name = "dotenv" | ||
name = "dotenvy" | ||
required-features = ["cli"] | ||
|
||
[dependencies] | ||
clap = { version = "2", optional = true } | ||
clap = { version = "3.1", optional = true } | ||
dirs = "4.0" | ||
|
||
[dev-dependencies] | ||
tempfile = "3.0.0" | ||
tempfile = "3.3.0" | ||
|
||
[features] | ||
cli = ["clap"] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Why were all this example code removed? I think they are helpful.