Skip to content

Commit

Permalink
code
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanhonof committed Oct 26, 2024
1 parent ef1b25b commit 605f195
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/libcmd/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,12 @@ MixEnvironment::MixEnvironment()
.description = "Unset the environment variable *name*.",
.category = environmentVariablesCategory,
.labels = {"name"},
.handler = {[&](std::string s) { unsetVars.insert(s); }},
.handler = {[&](std::string name) {
if (setVars.contains(name))
throw UsageError("Cannot unset environment variable '%s' that is set with '%s'", name, "--set-env-var");

unsetVars.insert(name);
}},
});

addFlag({
Expand All @@ -327,9 +332,14 @@ MixEnvironment::MixEnvironment()
.category = environmentVariablesCategory,
.labels = {"name", "value"},
.handler = {[&](std::string name, std::string value) {
if (unsetVars.contains(name))
throw UsageError(
"Cannot set environment variable '%s' that is unset with '%s'", name, "--unset-env-var");

if (setVars.contains(name))
throw UsageError(
"Duplicate definition of environment variable '%s' with '%s' is ambiguous", name, "--set-env-var");

setVars.insert_or_assign(name, value);
}},
});
Expand Down

0 comments on commit 605f195

Please sign in to comment.