Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update dependencies and rust edition #76

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
42 changes: 35 additions & 7 deletions CHANGELOG.md
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))

### 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))
- assertions dealing with `Result` (based on [dotenv-rs/dotenv #57](https://github.com/dotenv-rs/dotenv/pull/57))
- upgraded clap in `dotenvy` bin from v2 to v3.1 (covers [dotenv-rs/dotenv #76](https://github.com/dotenv-rs/dotenv/pull/76))

## [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
6 changes: 1 addition & 5 deletions Cargo.toml
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"]
2 changes: 1 addition & 1 deletion LICENSE.md → LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.
130 changes: 31 additions & 99 deletions README.md
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/dotenvy)
![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`](https://crates.io/crates/dotenvy) crate - A well-maintained fork of the `dotenv` crate.
2. [`dotenvy_macro`](https://crates.io/crates/dotenvy_codegen) crate - A macro for compile time dotenv inspection. This is a fork of `dotenv_codegen`.
3. [`dotenvy_codgen_impl`](https://crates.io/crates/dotenvy_codegen_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_macro` 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
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))

# 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
```
## The legend

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!
24 changes: 13 additions & 11 deletions dotenv/Cargo.toml
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 <noemi.lapresta@gmail.com>",
"Craig Hills <chills@gmail.com>",
Expand All @@ -9,24 +9,26 @@ authors = [
"Sean Griffin <sean@seantheprogrammer.com>",
"Adam Sharp <adam@sharplet.me>",
"Arpad Borsos <arpad.borsos@googlemail.com>",
"Allan Zhang <al@ayz.ai>",
]
description = "A `dotenv` implementation for Rust"
homepage = "https://github.com/dotenv-rs/dotenv"
readme = "../README.md"
keywords = ["environment", "env", "dotenv", "settings", "config"]
description = "A well-maintained fork of the `dotenv` crate"
homepage = "https://github.com/allan2/dotenvy"
readme = "README.md"
keywords = ["dotenv", "env", "environment", "settings", "config"]
license = "MIT"
repository = "https://github.com/dotenv-rs/dotenv"
edition = "2018"
repository = "https://github.com/allan2/dotenvy"
edition = "2021"

[[bin]]
name = "dotenv"
name = "dotenvy"
required-features = ["cli"]

[dependencies]
clap = { version = "2", optional = true }
clap = { version = "3.1.6", optional = true }
dirs = "4.0"

[dev-dependencies]
tempfile = "3.0.0"
tempfile = "3.3.0"

[features]
cli = ["clap"]
57 changes: 57 additions & 0 deletions dotenv/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# dotenvy

[![crates.io](https://img.shields.io/crates/v/dotenvy.svg)](https://crates.io/crates/dotenvy)
[![Released API docs](https://docs.rs/dotenvy/badge.svg)](https://docs.rs/dotenvy)

A well-maintained fork of the [dotenv](https://github.com/dotenv-rs/dotenv) crate.

This library loads environment variables from a _.env_ file. This is convenient for dev environments.

## Components

1. [`dotenvy`](https://crates.io/crates/dotenvy) crate - A well-maintained fork of the `dotenv` crate.
2. [`dotenvy_codegen`](https://crates.io/crates/dotenvy_codegen) crate - A macro for compile time dotenv inspection.
3. [`dotenvy_codgen_impl`](https://crates.io/crates/dotenvy_codegen_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

### Loading at runtime

```rs
use dotenvy::dotenv;
use std::env;

fn main() {
dotenv().ok();

for (key, value) in env::vars() {
println!("{key}: {value}");
}
}
```

### Loading at compile time

The `dotenv!` macro provided by [`dotenvy_codegen`](https://crates.io/crates/dotenvy_codegen) can be used.

## Why does this fork exist?

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)).

This fork is intended to serve as the development home for the dotenv implementation in Rust.

## What are the differences from the original?

This repo fixes:

- 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))

For a full list of changes, read the [changelog](./CHANGELOG.md).

## The legend

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.

Until then, this repo dutifully carries on the dotenv torch. It is actively maintained. Contributions and PRs are very welcome!
10 changes: 0 additions & 10 deletions dotenv/examples/simple.rs

This file was deleted.

Loading