1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-19 10:50:24 -04:00

profile: add --regex option to match packages

This commit is contained in:
Bob van der Linden 2024-03-07 20:33:59 +01:00
parent d6f5da51d3
commit 87741dbd21
No known key found for this signature in database
4 changed files with 21 additions and 3 deletions

View file

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

View file

@ -6,7 +6,7 @@ R""(
reference:
```console
# nix profile upgrade '.*'
# nix profile upgrade --regex '.*'
```
* Upgrade a specific package by name:

View file

@ -508,7 +508,15 @@ public:
MixProfileElementMatchers()
{
expectArgs(ExpectedArg {
addFlag({
.longName = "regex",
.description = "A regular expression to match one or more packages in the profile.",
.labels = {"pattern"},
.handler = {[this](std::string arg) {
_matchers.push_back(createRegexMatcher(arg));
}},
});
expectArgs({
.label = "elements",
.optional = true,
.handler = {[this](std::vector<std::string> args) {

View file

@ -71,6 +71,16 @@ nix profile upgrade flake1
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello NixOS" ]]
nix profile history | grep "packages.$system.default: 1.0, 1.0-man -> 2.0, 2.0-man"
# Test upgrading package using regular expression.
printf 2.1 > $flake1Dir/version
nix profile upgrade --regex '.*'
[[ $(readlink $TEST_HOME/.nix-profile/bin/hello) =~ .*-profile-test-2\.1/bin/hello ]]
nix profile rollback
# Test removing all packages using regular expression.
nix profile remove --regex '.*' 2>&1 | grep "removed 2 packages, kept 0 packages"
nix profile rollback
# Test 'history', 'diff-closures'.
nix profile diff-closures