Skip to content

Commit

Permalink
Add Find-Package (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasNieto authored Sep 17, 2024
1 parent 07f5c30 commit 7a96d66
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/AnyPackage.Pkgx.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@ using module AnyPackage
using namespace AnyPackage.Provider

[PackageProvider('pkgx')]
class PkgxProvider : PackageProvider, IInstallPackage, IUninstallPackage {
class PkgxProvider : PackageProvider, IFindPackage, IInstallPackage, IUninstallPackage {
[void] FindPackage([PackageRequest] $request) {
if ($request.Name -eq '*') {
$request.WriteVerbose('pkgx does not support wildcards.')
return
}

pkgx mash pkgx/pantry-inventory $request.Name |
ForEach-Object {
if ($request.IsMatch([PackageVersion]$_)) {
$package = [PackageInfo]::new($request.Name, $_, $request.ProviderInfo)
$request.WritePackage($package)
}
}
}

[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.'
Expand Down
10 changes: 10 additions & 0 deletions tests/Find-Package.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#Requires -Modules AnyPackage.Pkgx

Describe Find-Package {
Context 'with -Name parameter' {
It 'should find' {
{ Find-Package -Name bun } |
Should -Not -BeNullOrEmpty
}
}
}
2 changes: 1 addition & 1 deletion tests/Install-Package.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Describe Install-Package {
Should -Not -Throw
}
}
}
}

0 comments on commit 7a96d66

Please sign in to comment.