Skip to content

Commit

Permalink
\#61 Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jharrilim committed Aug 23, 2020
1 parent b6357f9 commit b04a289
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
target/
Cargo.lock
.idea
wip
2 changes: 1 addition & 1 deletion dotenv_codegen/tests/ui/dotenv_no_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ extern crate dotenv_codegen;

pub fn main() {
dotenv!();
}
}
2 changes: 1 addition & 1 deletion dotenv_codegen/tests/ui/dotenv_or_default_no_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ extern crate dotenv_codegen;

pub fn main() {
dotenv_or_default!();
}
}
2 changes: 1 addition & 1 deletion dotenv_codegen/tests/ui/dotenv_or_default_three_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ extern crate dotenv_codegen;

pub fn main() {
dotenv_or_default!("a", "b", "c");
}
}
2 changes: 1 addition & 1 deletion dotenv_codegen/tests/ui/dotenv_three_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ extern crate dotenv_codegen;

pub fn main() {
dotenv!("a", "b", "c");
}
}
19 changes: 12 additions & 7 deletions dotenv_codegen_implementation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,19 @@ pub fn dotenv_or_default(input: TokenStream) -> TokenStream {

// Either everything was fine, or we didn't find an .env file (which we ignore)
let (var_name, second_value) = expand_env(input);
let default_val = match second_value {
Some(default) => default,
None => panic!("Missing default value for: {}", var_name),
};

match env::var(var_name) {
Ok(val) => quote!(#val).into(),
Err(VarError::NotPresent) | Err(VarError::NotUnicode(_)) => quote!(#default_val).into(),
match second_value {
Some(default) => match env::var(var_name) {
Ok(val) => quote!(#val).into(),
Err(VarError::NotPresent) | Err(VarError::NotUnicode(_)) => quote!(#default).into(),
},
None => {
let err_msg = format!("Missing default value for: {}", var_name);
(quote! {
compile_error!(#err_msg)
})
.into()
}
}
}

Expand Down

0 comments on commit b04a289

Please sign in to comment.