Skip to content

Commit 27ef7cc

Browse files
committed
Add Optimize-Package
1 parent 0c2e334 commit 27ef7cc

7 files changed

+64
-8
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"cSpell.words": [
33
"cuda",
4-
"Nieto"
4+
"Nieto",
5+
"nirsoft"
56
]
67
}

src/AnyPackage.Scoop.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
Description = 'Scoop provider for AnyPackage.'
99
PowerShellVersion = '5.1'
1010
RequiredModules = @(
11-
@{ ModuleName = 'AnyPackage'; ModuleVersion = '0.6.0' },
12-
@{ ModuleName = 'Scoop'; ModuleVersion = '0.2.0' })
11+
@{ ModuleName = 'AnyPackage'; ModuleVersion = '0.9.0' },
12+
@{ ModuleName = 'Scoop'; ModuleVersion = '0.3.0' })
1313
FunctionsToExport = @()
1414
CmdletsToExport = @()
1515
AliasesToExport = @()

src/AnyPackage.Scoop.psm1

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ using namespace System.Threading
1313

1414
[PackageProvider('Scoop')]
1515
class ScoopProvider : PackageProvider, IFindPackage, IGetPackage,
16-
IInstallPackage, IUpdatePackage, IUninstallPackage, IGetSource, ISetSource, ICommandNotFound {
16+
IInstallPackage, IOptimizePackage, IUpdatePackage, IUninstallPackage, IGetSource, ISetSource, ICommandNotFound {
1717
[PackageProviderInfo] Initialize([PackageProviderInfo] $providerInfo) {
1818
return [ScoopProviderInfo]::new($providerInfo)
1919
}
@@ -79,6 +79,24 @@ IInstallPackage, IUpdatePackage, IUninstallPackage, IGetSource, ISetSource, ICom
7979
Write-Package -Request $request -OfficialSources $this.ProviderInfo.OfficialSources
8080
}
8181

82+
[void] OptimizePackage([PackageRequest] $request) {
83+
$optimizeScoopAppParams = @{ }
84+
85+
if ($request.DynamicParameters.Scope -eq 'AllUsers') {
86+
$optimizeScoopAppParams['Global'] = $true
87+
}
88+
89+
if ($request.DynamicParameters.DownloadCache) {
90+
$optimizeScoopAppParams['DownloadCache'] = $request.DynamicParameters.DownloadCache
91+
}
92+
93+
Get-ScoopApp -Name $request.Name |
94+
Optimize-ScoopApp @optimizeScoopAppParams
95+
96+
Get-ScoopApp -Name $request.Name |
97+
Write-Package -Request $request -OfficialSources $this.ProviderInfo.OfficialSources
98+
}
99+
82100
[void] UpdatePackage([PackageRequest] $request) {
83101
$installScoopAppParams = @{ }
84102

@@ -201,6 +219,7 @@ IInstallPackage, IUpdatePackage, IUninstallPackage, IGetSource, ISetSource, ICom
201219
return $(switch ($commandName) {
202220
'Register-PackageSource' { [RegisterPackageSourceDynamicParameters]::new() }
203221
'Install-Package' { [InstallPackageDynamicParameters]::new() }
222+
'Optimize-Package' { [OptimizePackageDynamicParameters]::new() }
204223
'Uninstall-Package' { [UninstallPackageDynamicParameters]::new() }
205224
'Update-Package' { [UpdatePackageDynamicParameters]::new() }
206225
default { $null }
@@ -256,6 +275,12 @@ class UninstallPackageDynamicParameters : ScopeDynamicParameters {
256275
$RemoveData
257276
}
258277

278+
class OptimizePackageDynamicParameters : ScopeDynamicParameters {
279+
[Parameter()]
280+
[switch]
281+
$DownloadCache
282+
}
283+
259284
class ScoopProviderInfo : PackageProviderInfo {
260285
[hashtable] $OfficialSources
261286
[Dictionary[string, List[ScoopAppDetailed]]] $CommandCache = [Dictionary[string, List[ScoopAppDetailed]]]::new([StringComparer]::OrdinalIgnoreCase)

test/Install-Package.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Describe Install-Package {
2929
}
3030

3131
Context 'with -SkipDependencies parameter' {
32-
It 'should install wihout dependency' {
32+
It 'should install without dependency' {
3333
{ Install-Package -Provider Scoop -Name z.lua -SkipDependencies -ErrorAction Stop } |
3434
Should -Not -Throw
3535

test/Optimize-Package.Tests.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#Requires -Modules AnyPackage.Scoop
2+
3+
Describe Optimize-Package {
4+
BeforeAll {
5+
Install-ScoopApp -Name 7zip, abc
6+
}
7+
8+
AfterAll {
9+
Uninstall-ScoopApp -Name 7zip, abc
10+
}
11+
12+
Context 'with no parameters' {
13+
It 'should not throw' {
14+
{ Optimize-Package -ErrorAction Stop } |
15+
Should -Not -Throw
16+
}
17+
}
18+
19+
Context 'with -Name parameter' {
20+
It 'with 7zip should not throw' {
21+
{ Optimize-Package -Name 7zip -ErrorAction Stop } |
22+
Should -Not -Throw
23+
}
24+
25+
It 'with broke should throw' {
26+
{ Optimize-Package -Name broke -ErrorAction Stop } |
27+
Should -Throw
28+
}
29+
}
30+
}

test/Uninstall-Package.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Describe Uninstall-Package {
1616
It 'should install' {
1717
# TODO: Fix 22.0 parse
1818
{ Uninstall-Package -Name 7zip -Version '22.01' -ErrorAction Stop } |
19-
Should -Not -Throw
19+
Should -Not -
2020
}
2121

2222
It 'should install' {

test/Update-Package.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Describe Update-Package {
99
Uninstall-ScoopApp -Name 7zip -ErrorAction Ignore
1010
}
1111

12-
Context 'with no paramters' {
12+
Context 'with no parameters' {
1313
It 'should update' {
1414
{ Update-Package -ErrorAction Stop } |
1515
Should -Not -Throw
@@ -24,7 +24,7 @@ Describe Update-Package {
2424
}
2525

2626
Context 'with -SkipDependencies parameter' {
27-
It 'should update wihout dependency' {
27+
It 'should update without dependency' {
2828
{ Update-Package -Provider Scoop -SkipDependencies -ErrorAction Stop } |
2929
Should -Not -Throw
3030
}

0 commit comments

Comments
 (0)