Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Envish
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Libraries
Envish
Commits
82b69a23
Verified
Commit
82b69a23
authored
4 months ago
by
Louis
Browse files
Options
Downloads
Patches
Plain Diff
Fmt & Lint
parent
9af6ca8c
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
rustfmt.toml
+4
-0
4 additions, 0 deletions
rustfmt.toml
src/env_file.rs
+15
-19
15 additions, 19 deletions
src/env_file.rs
src/filesystem.rs
+2
-3
2 additions, 3 deletions
src/filesystem.rs
src/lib.rs
+2
-2
2 additions, 2 deletions
src/lib.rs
tests/integration.rs
+26
-26
26 additions, 26 deletions
tests/integration.rs
with
49 additions
and
50 deletions
rustfmt.toml
0 → 100644
+
4
−
0
View file @
82b69a23
hard_tabs
=
true
reorder_imports
=
true
max_width
=
140
merge_derives
=
true
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/env_file.rs
+
15
−
19
View file @
82b69a23
use
crate
::
parser
::{
file
,
FileLine
};
use
nom_locate
::
LocatedSpan
;
use
std
::
env
;
use
std
::
env
::
VarError
;
use
std
::
fmt
::
Display
;
use
crate
::
parser
::{
file
,
FileLine
};
use
nom_locate
::
LocatedSpan
;
use
std
::
str
::
FromStr
;
use
std
::
string
::
ParseError
;
...
...
@@ -114,9 +114,9 @@ pub struct ApplyOptions {
impl
ApplyOptions
{
pub
fn
new
(
prefix
:
impl
Display
,
overwrite
:
bool
)
->
Self
{
Self
{
prefix
:
Some
(
prefix
.to_string
()),
overwrite
,
}
prefix
:
Some
(
prefix
.to_string
()),
overwrite
,
}
}
pub
fn
with_prefix
(
prefix
:
impl
Display
)
->
Self
{
...
...
@@ -124,10 +124,7 @@ impl ApplyOptions {
}
pub
fn
with_overwrite
(
overwrite
:
bool
)
->
Self
{
Self
{
prefix
:
None
,
overwrite
,
}
Self
{
prefix
:
None
,
overwrite
}
}
}
...
...
@@ -141,20 +138,20 @@ impl ApplyEnvironmentFile for EnvironmentFile {
}
}
impl
<
E
>
ApplyEnvironmentFile
for
Result
<
EnvironmentFile
,
E
>
{
impl
<
E
>
ApplyEnvironmentFile
for
Result
<
EnvironmentFile
,
E
>
{
fn
apply
(
&
self
,
options
:
ApplyOptions
)
{
if
let
Ok
(
file
)
=
self
{
file
.apply
(
options
);
}
}
if
let
Ok
(
file
)
=
self
{
file
.apply
(
options
);
}
}
}
impl
ApplyEnvironmentFile
for
Option
<
EnvironmentFile
>
{
fn
apply
(
&
self
,
options
:
ApplyOptions
)
{
if
let
Some
(
file
)
=
self
{
file
.apply
(
options
);
}
}
if
let
Some
(
file
)
=
self
{
file
.apply
(
options
);
}
}
}
pub
struct
EnvFileIterator
<
'a
>
{
...
...
@@ -251,7 +248,6 @@ fn set_from_file(file: &EnvironmentFile, options: ApplyOptions) -> Result<(), En
Ok
(())
}
#[cfg(test)]
mod
tests
{
use
super
::
*
;
...
...
This diff is collapsed.
Click to expand it.
src/filesystem.rs
+
2
−
3
View file @
82b69a23
use
crate
::{
EnvironmentFile
};
use
crate
::
env_file
::{
ApplyEnvironmentFile
,
ApplyOptions
};
use
crate
::
EnvironmentFile
;
use
std
::
fmt
::
Display
;
use
std
::
fs
::
File
;
use
std
::
io
::
Read
;
use
std
::
path
::
Path
;
use
crate
::
env_file
::{
ApplyEnvironmentFile
,
ApplyOptions
};
#[derive(Debug,
thiserror::Error)]
#[allow(clippy::enum_variant_names)]
...
...
@@ -49,4 +49,3 @@ pub fn dotenv_from(path: impl AsRef<Path>) -> Result<(), EnvFsError> {
env_file_from_path
(
path
)
?
.apply
(
Default
::
default
());
Ok
(())
}
This diff is collapsed.
Click to expand it.
src/lib.rs
+
2
−
2
View file @
82b69a23
...
...
@@ -5,8 +5,8 @@ mod env_file;
mod
filesystem
;
mod
parser
;
pub
use
env_file
::{
EnvironmentFile
,
EnvironmentFileError
,
ApplyEnvironmentFile
,
ApplyOptions
};
pub
use
env_file
::{
ApplyEnvironmentFile
,
ApplyOptions
,
EnvironmentFile
,
EnvironmentFileError
};
pub
use
parser
::{
FileLine
,
ValuePart
};
#[cfg(feature
=
"fs"
)]
pub
use
filesystem
::{
dotenv
,
dotenv_from
,
dotenv_
suffix
,
dotenv_
opts
};
pub
use
filesystem
::{
dotenv
,
dotenv_from
,
dotenv_
opts
,
dotenv_
suffix
};
This diff is collapsed.
Click to expand it.
tests/integration.rs
+
26
−
26
View file @
82b69a23
...
...
@@ -2,7 +2,7 @@ use envish::{ApplyEnvironmentFile, ApplyOptions, EnvironmentFile};
#[test]
fn
it_parses_basic_dotenv_file
()
{
let
file_contents
=
r#"
let
file_contents
=
r#"
# This value won't be set in the test, and this comment will be ignored
MY_BEST_VARIABLE=some_value
# This variable is also not defined, and it'll still be a string,
...
...
@@ -10,19 +10,19 @@ fn it_parses_basic_dotenv_file() {
SOME_OTHER_VARIABLE=1234
"#
;
std
::
env
::
var
(
"MY_BEST_VARIABLE"
)
.expect_err
(
"MY_BEST_VARIABLE should not be set"
);
std
::
env
::
var
(
"SOME_OTHER_VARIABLE"
)
.expect_err
(
"SOME_OTHER_VARIABLE should not be set"
);
std
::
env
::
var
(
"MY_BEST_VARIABLE"
)
.expect_err
(
"MY_BEST_VARIABLE should not be set"
);
std
::
env
::
var
(
"SOME_OTHER_VARIABLE"
)
.expect_err
(
"SOME_OTHER_VARIABLE should not be set"
);
let
file
=
EnvironmentFile
::
parse
(
file_contents
)
.expect
(
"Failed to parse environment file"
);
file
.apply
(
Default
::
default
());
let
file
=
EnvironmentFile
::
parse
(
file_contents
)
.expect
(
"Failed to parse environment file"
);
file
.apply
(
Default
::
default
());
assert_eq!
(
std
::
env
::
var
(
"MY_BEST_VARIABLE"
)
.unwrap
(),
"some_value"
);
assert_eq!
(
std
::
env
::
var
(
"SOME_OTHER_VARIABLE"
)
.unwrap
(),
"1234"
);
assert_eq!
(
std
::
env
::
var
(
"MY_BEST_VARIABLE"
)
.unwrap
(),
"some_value"
);
assert_eq!
(
std
::
env
::
var
(
"SOME_OTHER_VARIABLE"
)
.unwrap
(),
"1234"
);
}
#[test]
fn
it_parses_dotenv_file_with_interpolation
()
{
let
file_contents
=
r#"
let
file_contents
=
r#"
# This value won't be set in the test, and this comment will be ignored
MY_BEST_VARIABLE=some_value
# This variable is also not defined, and it'll still be a string,
...
...
@@ -32,21 +32,21 @@ fn it_parses_dotenv_file_with_interpolation() {
INTERPOLATED_VARIABLE=${SOME_OTHER_VARIABLE}567
"#
;
std
::
env
::
var
(
"MY_BEST_VARIABLE"
)
.expect_err
(
"MY_BEST_VARIABLE should not be set"
);
std
::
env
::
var
(
"SOME_OTHER_VARIABLE"
)
.expect_err
(
"SOME_OTHER_VARIABLE should not be set"
);
std
::
env
::
var
(
"INTERPOLATED_VARIABLE"
)
.expect_err
(
"INTERPOLATED_VARIABLE should not be set"
);
std
::
env
::
var
(
"MY_BEST_VARIABLE"
)
.expect_err
(
"MY_BEST_VARIABLE should not be set"
);
std
::
env
::
var
(
"SOME_OTHER_VARIABLE"
)
.expect_err
(
"SOME_OTHER_VARIABLE should not be set"
);
std
::
env
::
var
(
"INTERPOLATED_VARIABLE"
)
.expect_err
(
"INTERPOLATED_VARIABLE should not be set"
);
let
file
=
EnvironmentFile
::
parse
(
file_contents
)
.expect
(
"Failed to parse environment file"
);
file
.apply
(
Default
::
default
());
let
file
=
EnvironmentFile
::
parse
(
file_contents
)
.expect
(
"Failed to parse environment file"
);
file
.apply
(
Default
::
default
());
assert_eq!
(
std
::
env
::
var
(
"MY_BEST_VARIABLE"
)
.unwrap
(),
"some_value"
);
assert_eq!
(
std
::
env
::
var
(
"SOME_OTHER_VARIABLE"
)
.unwrap
(),
"1234"
);
assert_eq!
(
std
::
env
::
var
(
"INTERPOLATED_VARIABLE"
)
.unwrap
(),
"1234567"
);
assert_eq!
(
std
::
env
::
var
(
"MY_BEST_VARIABLE"
)
.unwrap
(),
"some_value"
);
assert_eq!
(
std
::
env
::
var
(
"SOME_OTHER_VARIABLE"
)
.unwrap
(),
"1234"
);
assert_eq!
(
std
::
env
::
var
(
"INTERPOLATED_VARIABLE"
)
.unwrap
(),
"1234567"
);
}
#[test]
fn
it_parses_dotenv_file_with_interpolation_and_prefix_option
()
{
let
file_contents
=
r#"
let
file_contents
=
r#"
# This value won't be set in the test, and this comment will be ignored
MY_BEST_VARIABLE=some_value
# This variable is also not defined, and it'll still be a string,
...
...
@@ -56,14 +56,14 @@ fn it_parses_dotenv_file_with_interpolation_and_prefix_option() {
INTERPOLATED_VARIABLE=${SOME_OTHER_VARIABLE}567
"#
;
std
::
env
::
var
(
"MY_BEST_VARIABLE"
)
.expect_err
(
"MY_BEST_VARIABLE should not be set"
);
std
::
env
::
var
(
"SOME_OTHER_VARIABLE"
)
.expect_err
(
"SOME_OTHER_VARIABLE should not be set"
);
std
::
env
::
var
(
"INTERPOLATED_VARIABLE"
)
.expect_err
(
"INTERPOLATED_VARIABLE should not be set"
);
std
::
env
::
var
(
"MY_BEST_VARIABLE"
)
.expect_err
(
"MY_BEST_VARIABLE should not be set"
);
std
::
env
::
var
(
"SOME_OTHER_VARIABLE"
)
.expect_err
(
"SOME_OTHER_VARIABLE should not be set"
);
std
::
env
::
var
(
"INTERPOLATED_VARIABLE"
)
.expect_err
(
"INTERPOLATED_VARIABLE should not be set"
);
let
file
=
EnvironmentFile
::
parse
(
file_contents
)
.expect
(
"Failed to parse environment file"
);
file
.apply
(
ApplyOptions
::
with_prefix
(
"APP_"
));
let
file
=
EnvironmentFile
::
parse
(
file_contents
)
.expect
(
"Failed to parse environment file"
);
file
.apply
(
ApplyOptions
::
with_prefix
(
"APP_"
));
assert_eq!
(
std
::
env
::
var
(
"APP_MY_BEST_VARIABLE"
)
.unwrap
(),
"some_value"
);
assert_eq!
(
std
::
env
::
var
(
"APP_SOME_OTHER_VARIABLE"
)
.unwrap
(),
"1234"
);
assert_eq!
(
std
::
env
::
var
(
"APP_INTERPOLATED_VARIABLE"
)
.unwrap
(),
"1234567"
);
}
\ No newline at end of file
assert_eq!
(
std
::
env
::
var
(
"APP_MY_BEST_VARIABLE"
)
.unwrap
(),
"some_value"
);
assert_eq!
(
std
::
env
::
var
(
"APP_SOME_OTHER_VARIABLE"
)
.unwrap
(),
"1234"
);
assert_eq!
(
std
::
env
::
var
(
"APP_INTERPOLATED_VARIABLE"
)
.unwrap
(),
"1234567"
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment