winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 7b82c8593a21e35a597ed1a3f76be50d645d4b11
parent ad0337871964951de642bfc778bc558ee4190e00
Author: Ryan <69221034+ryfu-msft@users.noreply.github.com>
Date:   Fri,  8 Dec 2023 12:49:43 -0800

Add package id, name, and source to install/update/uninstall result for PowerShell cmdlet (#3954)


Diffstat:
Msrc/PowerShell/Microsoft.WinGet.Client.Engine/Commands/Common/PackageCommand.cs | 5+++--
Msrc/PowerShell/Microsoft.WinGet.Client.Engine/Commands/InstallerPackageCommand.cs | 5++---
Msrc/PowerShell/Microsoft.WinGet.Client.Engine/Commands/UninstallPackageCommand.cs | 2+-
Msrc/PowerShell/Microsoft.WinGet.Client.Engine/PSObjects/PSInstallResult.cs | 39+++++++++++++++++++++++++++++++++++++--
Msrc/PowerShell/Microsoft.WinGet.Client.Engine/PSObjects/PSUninstallResult.cs | 41++++++++++++++++++++++++++++++++++++++---
Msrc/PowerShell/Microsoft.WinGet.Client/ModuleFiles/Format.ps1xml | 36++++++++++++++++++++++++++++++++++++
Msrc/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 | 21+++++++++++++++++++++
7 files changed, 138 insertions(+), 11 deletions(-)

diff --git a/src/PowerShell/Microsoft.WinGet.Client.Engine/Commands/Common/PackageCommand.cs b/src/PowerShell/Microsoft.WinGet.Client.Engine/Commands/Common/PackageCommand.cs @@ -57,7 +57,7 @@ namespace Microsoft.WinGet.Client.Engine.Commands.Common /// <param name="match">The match option.</param> /// <param name="callback">The method to call after retrieving the package and version to operate upon.</param> /// <returns>Result of the callback.</returns> - protected async Task<TResult?> GetPackageAndExecuteAsync<TResult>( + protected async Task<Tuple<TResult, CatalogPackage>?> GetPackageAndExecuteAsync<TResult>( CompositeSearchBehavior behavior, PackageFieldMatchOption match, Func<CatalogPackage, PackageVersionId?, Task<TResult>> callback) @@ -67,7 +67,8 @@ namespace Microsoft.WinGet.Client.Engine.Commands.Common PackageVersionId? version = this.GetPackageVersionId(package); if (this.ShouldProcess(package.ToString(version))) { - return await callback(package, version); + var result = await callback(package, version); + return new Tuple<TResult, CatalogPackage>(result, package); } return null; diff --git a/src/PowerShell/Microsoft.WinGet.Client.Engine/Commands/InstallerPackageCommand.cs b/src/PowerShell/Microsoft.WinGet.Client.Engine/Commands/InstallerPackageCommand.cs @@ -108,13 +108,12 @@ namespace Microsoft.WinGet.Client.Engine.Commands } options.PackageInstallScope = PSEnumHelpers.ToPackageInstallScope(psPackageInstallScope); - return await this.InstallPackageAsync(package, options); })); if (result != null) { - this.Write(StreamType.Object, new PSInstallResult(result)); + this.Write(StreamType.Object, new PSInstallResult(result.Item1, result.Item2)); } } @@ -142,7 +141,7 @@ namespace Microsoft.WinGet.Client.Engine.Commands if (result != null) { - this.Write(StreamType.Object, new PSInstallResult(result)); + this.Write(StreamType.Object, new PSInstallResult(result.Item1, result.Item2)); } } diff --git a/src/PowerShell/Microsoft.WinGet.Client.Engine/Commands/UninstallPackageCommand.cs b/src/PowerShell/Microsoft.WinGet.Client.Engine/Commands/UninstallPackageCommand.cs @@ -84,7 +84,7 @@ namespace Microsoft.WinGet.Client.Engine.Commands if (result != null) { - this.Write(StreamType.Object, new PSUninstallResult(result)); + this.Write(StreamType.Object, new PSUninstallResult(result.Item1, result.Item2)); } } diff --git a/src/PowerShell/Microsoft.WinGet.Client.Engine/PSObjects/PSInstallResult.cs b/src/PowerShell/Microsoft.WinGet.Client.Engine/PSObjects/PSInstallResult.cs @@ -7,7 +7,6 @@ namespace Microsoft.WinGet.Client.Engine.PSObjects { using System; - using System.Management.Automation; using Microsoft.Management.Deployment; /// <summary> @@ -16,14 +15,50 @@ namespace Microsoft.WinGet.Client.Engine.PSObjects public sealed class PSInstallResult { private readonly InstallResult installResult; + private readonly CatalogPackage catalogPackage; /// <summary> /// Initializes a new instance of the <see cref="PSInstallResult"/> class. /// </summary> /// <param name="installResult">The install result COM object.</param> - internal PSInstallResult(InstallResult installResult) + /// <param name="catalogPackage">The catalog package COM object.</param> + internal PSInstallResult(InstallResult installResult, CatalogPackage catalogPackage) { this.installResult = installResult; + this.catalogPackage = catalogPackage; + } + + /// <summary> + /// Gets the id of the installed package. + /// </summary> + public string Id + { + get + { + return this.catalogPackage.Id; + } + } + + /// <summary> + /// Gets the name of the installed package. + /// </summary> + public string Name + { + get + { + return this.catalogPackage.Name; + } + } + + /// <summary> + /// Gets the source name of the installed package. + /// </summary> + public string Source + { + get + { + return this.catalogPackage.DefaultInstallVersion.PackageCatalog.Info.Name; + } } /// <summary> diff --git a/src/PowerShell/Microsoft.WinGet.Client.Engine/PSObjects/PSUninstallResult.cs b/src/PowerShell/Microsoft.WinGet.Client.Engine/PSObjects/PSUninstallResult.cs @@ -7,7 +7,6 @@ namespace Microsoft.WinGet.Client.Engine.PSObjects { using System; - using System.Management.Automation; using Microsoft.Management.Deployment; /// <summary> @@ -15,15 +14,51 @@ namespace Microsoft.WinGet.Client.Engine.PSObjects /// </summary> public sealed class PSUninstallResult { - private readonly Management.Deployment.UninstallResult uninstallResult; + private readonly UninstallResult uninstallResult; + private readonly CatalogPackage catalogPackage; /// <summary> /// Initializes a new instance of the <see cref="PSUninstallResult"/> class. /// </summary> /// <param name="uninstallResult">The uninstall result COM object.</param> - internal PSUninstallResult(Management.Deployment.UninstallResult uninstallResult) + /// <param name="catalogPackage">The catalog package COM object.</param> + internal PSUninstallResult(UninstallResult uninstallResult, CatalogPackage catalogPackage) { this.uninstallResult = uninstallResult; + this.catalogPackage = catalogPackage; + } + + /// <summary> + /// Gets the id of the uninstalled package. + /// </summary> + public string Id + { + get + { + return this.catalogPackage.Id; + } + } + + /// <summary> + /// Gets the name of the uninstalled package. + /// </summary> + public string Name + { + get + { + return this.catalogPackage.Name; + } + } + + /// <summary> + /// Gets the source name of the uninstalled package. + /// </summary> + public string Source + { + get + { + return this.catalogPackage.DefaultInstallVersion.PackageCatalog.Info.Name; + } } /// <summary> diff --git a/src/PowerShell/Microsoft.WinGet.Client/ModuleFiles/Format.ps1xml b/src/PowerShell/Microsoft.WinGet.Client/ModuleFiles/Format.ps1xml @@ -95,6 +95,15 @@ <TableControl> <TableHeaders> <TableColumnHeader> + <Label>Id</Label> + </TableColumnHeader> + <TableColumnHeader> + <Label>Name</Label> + </TableColumnHeader> + <TableColumnHeader> + <Label>Source</Label> + </TableColumnHeader> + <TableColumnHeader> <Label>InstallerErrorCode</Label> </TableColumnHeader> <TableColumnHeader> @@ -114,6 +123,15 @@ <TableRowEntry> <TableColumnItems> <TableColumnItem> + <ScriptBlock>$_.Id</ScriptBlock> + </TableColumnItem> + <TableColumnItem> + <ScriptBlock>$_.Name</ScriptBlock> + </TableColumnItem> + <TableColumnItem> + <ScriptBlock>$_.Source</ScriptBlock> + </TableColumnItem> + <TableColumnItem> <ScriptBlock>$_.InstallerErrorCode</ScriptBlock> </TableColumnItem> <TableColumnItem> @@ -141,6 +159,15 @@ <TableControl> <TableHeaders> <TableColumnHeader> + <Label>Id</Label> + </TableColumnHeader> + <TableColumnHeader> + <Label>Name</Label> + </TableColumnHeader> + <TableColumnHeader> + <Label>Source</Label> + </TableColumnHeader> + <TableColumnHeader> <Label>UninstallerErrorCode</Label> </TableColumnHeader> <TableColumnHeader> @@ -160,6 +187,15 @@ <TableRowEntry> <TableColumnItems> <TableColumnItem> + <ScriptBlock>$_.Id</ScriptBlock> + </TableColumnItem> + <TableColumnItem> + <ScriptBlock>$_.Name</ScriptBlock> + </TableColumnItem> + <TableColumnItem> + <ScriptBlock>$_.Source</ScriptBlock> + </TableColumnItem> + <TableColumnItem> <ScriptBlock>$_.UninstallerErrorCode</ScriptBlock> </TableColumnItem> <TableColumnItem> diff --git a/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 b/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 @@ -216,6 +216,9 @@ Describe 'Install|Update|Uninstall-WinGetPackage' { $result = Install-WinGetPackage -Id AppInstallerTest.TestExeInstaller -Version '1.0.0.0' $result | Should -Not -BeNullOrEmpty -ErrorAction Stop + $result.Id | Should -Be "AppInstallerTest.TestExeInstaller" + $result.Name | Should -Be "TestExeInstaller" + $result.Source | Should -Be "TestSource" $result.InstallerErrorCode | Should -Be 0 $result.Status | Should -Be 'Ok' $result.RebootRequired | Should -Be 'False' @@ -225,6 +228,9 @@ Describe 'Install|Update|Uninstall-WinGetPackage' { $result = Install-WinGetPackage -Name TestPortableExe -Version '2.0.0.0' -MatchOption Equals $result | Should -Not -BeNullOrEmpty -ErrorAction Stop + $result.Id | Should -Be "AppInstallerTest.TestPortableExe" + $result.Name | Should -Be "TestPortableExe" + $result.Source | Should -Be "TestSource" $result.InstallerErrorCode | Should -Be 0 $result.Status | Should -Be 'Ok' $result.RebootRequired | Should -Be 'False' @@ -234,6 +240,9 @@ Describe 'Install|Update|Uninstall-WinGetPackage' { $result = Update-WinGetPackage -Id AppInstallerTest.TestExeInstaller $result | Should -Not -BeNullOrEmpty -ErrorAction Stop + $result.Id | Should -Be "AppInstallerTest.TestExeInstaller" + $result.Name | Should -Be "TestExeInstaller" + $result.Source | Should -Be "TestSource" $result.InstallerErrorCode | Should -Be 0 $result.Status | Should -Be 'Ok' $result.RebootRequired | Should -Be 'False' @@ -243,6 +252,9 @@ Describe 'Install|Update|Uninstall-WinGetPackage' { $result = Update-WinGetPackage -Name TestPortableExe $result | Should -Not -BeNullOrEmpty -ErrorAction Stop + $result.Id | Should -Be "AppInstallerTest.TestPortableExe" + $result.Name | Should -Be "TestPortableExe" + $result.Source | Should -Be "TestSource" $result.InstallerErrorCode | Should -Be 0 $result.Status | Should -Be 'Ok' $result.RebootRequired | Should -Be 'False' @@ -252,6 +264,9 @@ Describe 'Install|Update|Uninstall-WinGetPackage' { $result = Uninstall-WinGetPackage -Id AppInstallerTest.TestExeInstaller $result | Should -Not -BeNullOrEmpty -ErrorAction Stop + $result.Id | Should -Be "AppInstallerTest.TestExeInstaller" + $result.Name | Should -Be "TestExeInstaller" + $result.Source | Should -Be "TestSource" $result.UninstallerErrorCode | Should -Be 0 $result.Status | Should -Be 'Ok' $result.RebootRequired | Should -Be 'False' @@ -261,6 +276,9 @@ Describe 'Install|Update|Uninstall-WinGetPackage' { $result = Uninstall-WinGetPackage -Name TestPortableExe $result | Should -Not -BeNullOrEmpty -ErrorAction Stop + $result.Id | Should -Be "AppInstallerTest.TestPortableExe" + $result.Name | Should -Be "TestPortableExe" + $result.Source | Should -Be "TestSource" $result.UninstallerErrorCode | Should -Be 0 $result.Status | Should -Be 'Ok' $result.RebootRequired | Should -Be 'False' @@ -292,6 +310,9 @@ Describe 'Get-WinGetPackage' { $result = Install-WinGetPackage -Id AppInstallerTest.TestExeInstaller -Version '1.0.0.0' $result | Should -Not -BeNullOrEmpty -ErrorAction Stop + $result.Id | Should -Be "AppInstallerTest.TestExeInstaller" + $result.Name | Should -Be "TestExeInstaller" + $result.Source | Should -Be "TestSource" $result.InstallerErrorCode | Should -Be 0 $result.Status | Should -Be 'Ok' $result.RebootRequired | Should -Be 'False'