Skip to content

Commit

Permalink
error out on unknown environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
WebFreak001 committed Aug 22, 2022
1 parent b8aa9a4 commit 4ee64c5
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions source/dub/project.d
Original file line number Diff line number Diff line change
Expand Up @@ -1519,11 +1519,23 @@ unittest
assert(expandVars!expandVar("$${DUB_EXE:-dub}") == "${DUB_EXE:-dub}");
}

string expandEnvironmentVariables(string s)
/// Expands the variables in the input string with the same rules as command
/// variables inside custom dub commands.
///
/// Params:
/// s = the input string where environment variables in form `$VAR` should be replaced
/// throwIfMissing = if true, throw an exception if the given variable is not found,
/// otherwise replace unknown variables with the empty string.
string expandEnvironmentVariables(string s, bool throwIfMissing = true)
{
import std.process : environment;

return expandVars!(v => environment.get(v))(s);
return expandVars!((v) {
auto ret = environment.get(v);
if (ret is null && throwIfMissing)
throw new Exception("Specified environment variable `$" ~ v ~ "` is not set");
return ret;
})(s);
}

// Keep the following list up-to-date if adding more build settings variables.
Expand Down

0 comments on commit 4ee64c5

Please sign in to comment.