Skip to content

Commit

Permalink
Add version range install (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasNieto authored Sep 21, 2024
1 parent 1563df4 commit 6b014c4
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 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 All @@ -24,7 +24,7 @@ class PkgxProvider : PackageProvider, IFindPackage, IGetPackage, IInstallPackage

[void] GetPackage([PackageRequest] $request) {
$pattern = 'exec pkgx \+(?<name>[\w\./]+)((?:[@^])(?<version>[\d\.]+))?'
$packages = Select-String -Path ./.local/bin/* -Pattern $pattern |
$packages = Select-String -Path ~/.local/bin/* -Pattern $pattern |
Select-Object -ExpandProperty Matches -Unique

$basePath = '~/.pkgx'
Expand Down Expand Up @@ -64,7 +64,17 @@ class PkgxProvider : PackageProvider, IFindPackage, IGetPackage, IInstallPackage

[void] InstallPackage([PackageRequest] $request) {
if ($request.Version -and $request.Version.MinVersion -ne $request.Version.MaxVersion) {
throw 'pkgx does not support version ranges, use only exact versions.'
$findPackageParams = @{
Name = $request.Name
Version = $request.Version
Provider = $request.ProviderInfo.FullName
}

$version = Find-Package @findPackageParams |
Sort-Object -Property Version -Descending |
Select-Object -ExpandProperty Version -First 1

$name = '{0}@{1}' -f $request.Name, $version
} elseif ($request.Version) {
$version = $request.Version.MinVersion
$name = '{0}@{1}' -f $request.Name, $version
Expand Down

0 comments on commit 6b014c4

Please sign in to comment.