profile: add --all option to match any package

This commit is contained in:
Bob van der Linden 2024-03-06 22:04:53 +01:00
parent fb391ebc77
commit 7a4d5e89d3
No known key found for this signature in database
4 changed files with 38 additions and 2 deletions

View file

@ -11,9 +11,16 @@ R""(
* Remove all packages: * Remove all packages:
```console ```console
# nix profile remove --regex '.*' # nix profile remove --all
``` ```
* Remove packages by regular expression:
```console
# nix profile remove --regex '.*vim.*'
```
* Remove a package by store path: * Remove a package by store path:
```console ```console

View file

@ -6,7 +6,7 @@ R""(
reference: reference:
```console ```console
# nix profile upgrade --regex '.*' # nix profile upgrade --all
``` ```
* Upgrade a specific package by name: * Upgrade a specific package by name:
@ -15,6 +15,12 @@ R""(
# nix profile upgrade hello # nix profile upgrade hello
``` ```
* Upgrade all packages that include 'vim' in their name:
```console
# nix profile upgrade --regex '.*vim.*'
```
# Description # Description
This command upgrades a previously installed package in a Nix profile, This command upgrades a previously installed package in a Nix profile,

View file

@ -458,6 +458,7 @@ enum MatcherType
Regex, Regex,
StorePath, StorePath,
Name, Name,
All,
}; };
struct Matcher struct Matcher
@ -500,6 +501,14 @@ Matcher createNameMatcher(const std::string & name) {
}; };
} }
Matcher all = {
.type = MatcherType::All,
.title = "--all",
.matches = [](const std::string &name, const ProfileElement & element) {
return true;
}
};
class MixProfileElementMatchers : virtual Args, virtual StoreCommand class MixProfileElementMatchers : virtual Args, virtual StoreCommand
{ {
std::vector<Matcher> _matchers; std::vector<Matcher> _matchers;
@ -508,6 +517,13 @@ public:
MixProfileElementMatchers() MixProfileElementMatchers()
{ {
addFlag({
.longName = "all",
.description = "Match all packages in the profile.",
.handler = {[this]() {
_matchers.push_back(all);
}},
});
addFlag({ addFlag({
.longName = "regex", .longName = "regex",
.description = "A regular expression to match one or more packages in the profile.", .description = "A regular expression to match one or more packages in the profile.",

View file

@ -77,6 +77,13 @@ nix profile upgrade --regex '.*'
[[ $(readlink $TEST_HOME/.nix-profile/bin/hello) =~ .*-profile-test-2\.1/bin/hello ]] [[ $(readlink $TEST_HOME/.nix-profile/bin/hello) =~ .*-profile-test-2\.1/bin/hello ]]
nix profile rollback nix profile rollback
# Test upgrading all packages
printf 2.2 > $flake1Dir/version
nix profile upgrade --all
[[ $(readlink $TEST_HOME/.nix-profile/bin/hello) =~ .*-profile-test-2\.2/bin/hello ]]
nix profile rollback
printf 1.0 > $flake1Dir/version
# 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.