Skip to content

Commit

Permalink
Fix uninstall allowing versions (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasNieto authored Sep 20, 2024
1 parent ddf814d commit 437cf7d
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/AnyPackage.Pkgx.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) Thomas Nieto - All Rights Reserved
# Copyright (c) Thomas Nieto - All Rights Reserved
# You may use, distribute and modify this code under the
# terms of the MIT license.

Expand Down Expand Up @@ -52,28 +52,19 @@ class PkgxProvider : PackageProvider, IFindPackage, IInstallPackage, IUninstallP
}

[void] UninstallPackage([PackageRequest] $request) {
if ($request.Version -and $request.Version.MinVersion -ne $request.Version.MaxVersion) {
throw 'pkgx does not support version ranges, use only exact versions.'
}
elseif ($request.Version) {
$version = $request.Version.MinVersion
$name = '{0}@{1}' -f $request.Name, $version
} elseif ($request.Name.Contains('@')) {
$name, $version = $request.Name -split '@'
} else {
$version = $null
$name = $request.Name
if ((-not $request.Package -and $request.Version) -or $request.Name.Contains('@')) {
throw 'pkgx does not support specifying version.'
}

$output = pkgx uninstall $name 2>&1 |
$output = pkgx uninstall $request.Name 2>&1 |
ForEach-Object {
$request.WriteVerbose($_)
$_
}

foreach ($line in $output) {
if ($line -match '^uninstalled:') {
$package = [PackageInfo]::new($name, $version, $request.ProviderInfo)
$package = [PackageInfo]::new($request.Name, $request.Package.Version, $request.ProviderInfo)
$request.WritePackage($package)
break
}
Expand Down

0 comments on commit 437cf7d

Please sign in to comment.