profile: make --all exclusive

This commit is contained in:
Bob van der Linden 2024-03-06 22:46:47 +01:00
parent 7a4d5e89d3
commit 91f068c193
No known key found for this signature in database
2 changed files with 15 additions and 0 deletions

View file

@ -554,6 +554,15 @@ public:
throw UsageError("No packages specified."); throw UsageError("No packages specified.");
} }
if (std::find_if(_matchers.begin(), _matchers.end(), [](const Matcher & m) { return m.type == MatcherType::All; }) != _matchers.end() && _matchers.size() > 1) {
throw UsageError("--all cannot be used with package names or regular expressions.");
}
if (manifest.elements.empty()) {
warn("There are no packages in the profile.");
return {};
}
std::set<std::string> result; std::set<std::string> result;
for (auto & matcher : _matchers) { for (auto & matcher : _matchers) {
bool foundMatch = false; bool foundMatch = false;

View file

@ -84,6 +84,12 @@ nix profile upgrade --all
nix profile rollback nix profile rollback
printf 1.0 > $flake1Dir/version printf 1.0 > $flake1Dir/version
# Test --all exclusivity.
assertStderr nix --offline profile upgrade --all foo << EOF
error: --all cannot be used with package names or regular expressions.
Try 'nix --help' for more information.
EOF
# Test matching no packages using literal package name. # Test matching no packages using literal package name.
assertStderr nix --offline profile upgrade this_package_is_not_installed << EOF assertStderr nix --offline profile upgrade this_package_is_not_installed << EOF
warning: Package name 'this_package_is_not_installed' does not match any packages in the profile. warning: Package name 'this_package_is_not_installed' does not match any packages in the profile.