From 8691cb362c63a970aec3a975c1c6be49a19311dc Mon Sep 17 00:00:00 2001 From: Ryan Yates Date: Mon, 9 Sep 2024 21:21:16 +0100 Subject: [PATCH 1/2] Updates to the PowerShell modules (#4716) --- .github/actions/spelling/expect.txt | 36 +++++++ .github/actions/spelling/patterns.txt | 3 + .../Disable-WinGetSetting.md | 4 +- .../Enable-WinGetSetting.md | 2 +- ...WinGetSettings.md => Get-WinGetSetting.md} | 14 +-- ...erSettings.md => Get-WinGetUserSetting.md} | 14 +-- .../Microsoft.WinGet.Client.md | 8 +- ...erSettings.md => Set-WinGetUserSetting.md} | 16 +-- ...rSettings.md => Test-WinGetUserSetting.md} | 14 +-- .../Cmdlets/AddSourceCmdlet.cs | 1 + .../AssertWinGetPackageManagerCmdlet.cs | 1 + .../Cmdlets/DisableSettingCmdlet.cs | 1 + .../Cmdlets/EnableSettingCmdlet.cs | 1 + .../Cmdlets/ExportPackageCmdlet.cs | 63 ++++++------ .../Cmdlets/FindPackageCmdlet.cs | 53 +++++----- .../Cmdlets/GetPackageCmdlet.cs | 1 + ...tSettingsCmdlet.cs => GetSettingCmdlet.cs} | 69 ++++++------- .../Cmdlets/GetSourceCmdlet.cs | 71 +++++++------- ...tingsCmdlet.cs => GetUserSettingCmdlet.cs} | 61 ++++++------ .../Cmdlets/GetVersionCmdlet.cs | 1 + .../Cmdlets/InstallPackageCmdlet.cs | 1 + .../Cmdlets/RemoveSourceCmdlet.cs | 1 + .../RepairWinGetPackageManagerCmdlet.cs | 1 + .../Cmdlets/ResetSourceCmdlet.cs | 1 + ...tingsCmdlet.cs => SetUserSettingCmdlet.cs} | 91 ++++++++--------- ...ingsCmdlet.cs => TestUserSettingCmdlet.cs} | 89 ++++++++--------- .../Cmdlets/UninstallPackageCmdlet.cs | 97 ++++++++++--------- .../Cmdlets/UpdatePackageCmdlet.cs | 67 ++++++------- .../Common/Constants.cs | 11 +-- .../Commands/UserSettingsCommand.cs | 6 +- .../ModuleFiles/Microsoft.WinGet.Client.psd1 | 32 +++++- .../Microsoft.WinGet.Client/README.md | 8 +- .../CompleteWinGetConfigurationCmdlet.cs | 1 + .../ConfirmWinGetConfigurationCmdlet.cs | 1 + .../ConvertToWinGetConfigurationYamlCmdlet.cs | 1 + .../Cmdlets/GetWinGetConfigurationCmdlet.cs | 1 + .../GetWinGetConfigurationDetailsCmdlet.cs | 1 + .../InvokeWinGetConfigurationCmdlet.cs | 1 + .../RemoveWinGetConfigurationHistoryCmdlet.cs | 1 + .../Cmdlets/StartWinGetConfigurationCmdlet.cs | 1 + .../Cmdlets/StopWinGetConfigurationCmdlet.cs | 1 + .../Cmdlets/TestWinGetConfigurationCmdlet.cs | 1 + .../Microsoft.WinGet.Configuration.psd1 | 2 +- .../Microsoft.WinGet.DSC.psm1 | 16 +-- .../tests/Microsoft.WinGet.Client.Tests.ps1 | 57 +++++------ .../tests/Microsoft.WinGet.DSC.Tests.ps1 | 4 +- 46 files changed, 507 insertions(+), 421 deletions(-) rename src/PowerShell/Help/Microsoft.WinGet.Client/{Get-WinGetSettings.md => Get-WinGetSetting.md} (88%) rename src/PowerShell/Help/Microsoft.WinGet.Client/{Get-WinGetUserSettings.md => Get-WinGetUserSetting.md} (79%) rename src/PowerShell/Help/Microsoft.WinGet.Client/{Set-WinGetUserSettings.md => Set-WinGetUserSetting.md} (87%) rename src/PowerShell/Help/Microsoft.WinGet.Client/{Test-WinGetUserSettings.md => Test-WinGetUserSetting.md} (86%) rename src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/{GetSettingsCmdlet.cs => GetSettingCmdlet.cs} (75%) rename src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/{GetUserSettingsCmdlet.cs => GetUserSettingCmdlet.cs} (77%) rename src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/{SetUserSettingsCmdlet.cs => SetUserSettingCmdlet.cs} (86%) rename src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/{TestUserSettingsCmdlet.cs => TestUserSettingCmdlet.cs} (88%) diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index 9c56b34984..1ecef0b368 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -45,6 +45,8 @@ ATL AType AUrl auxdata +awgpm +awgs azcopy azurewebsites Baz @@ -85,7 +87,10 @@ CLASSNOTREG CLOSEAPP cloudapp clsctx +clsid +cmpwgc CMSG +cnwgc cobertura CODEOWNERS codepage @@ -110,6 +115,7 @@ createmanifestmetadata cswinrt ctc CTL +ctwgcy currentuser dacl datetimeoffset @@ -134,6 +140,7 @@ dsc DUPLICATEALIAS dustojnikhummer dvinns +dwgs ecfr ecfrbrowse EFGH @@ -148,10 +155,13 @@ errstr ESRB etest etl +ewgp +ewgs execustom EXEHASH experimentalfeatures fdw +fdwgp FECAFEB fedorapeople fileinuse @@ -188,6 +198,13 @@ GRPICONDIR GRPICONDIRENTRY guiddef Gumbalapura +gwgc +gwgcd +gwgp +gwgse +gwgso +gwgus +gwgv Hackathon hashtables helplib @@ -233,8 +250,10 @@ isable ishelp ISQ ISVs +iswgp itr iwr +iwgc JArray JDictionary jdk @@ -354,6 +373,7 @@ NOSEPARATOR notalostreference NOTAPROPERTY NOTIMPL +notmatch NOTRACK NOUPDATE nowarn @@ -456,19 +476,25 @@ ronomon Roronoa rosoft rowid +rowids roy +rpwgpm RRF rrr +rswgs RTTI runspace runtimeclass runtimes +rwgch +rwgs ryfu sacl SARL sas SASURL savepoint +sawgc schematab Scm sddl @@ -503,6 +529,7 @@ SOURCESDIRECTORY sourceversion spamming SPAPI +spwgc sqlite Srinivasan SRL @@ -518,6 +545,7 @@ subkey Sudarshan superstring swervy +swgus SYD SYG sysrefcomp @@ -527,6 +555,8 @@ TARG taskhostw tcs TEMPDIRECTORY +templating +Templating temppath testexampleinstaller thiscouldbeapc @@ -537,11 +567,15 @@ tombstoned transitioning trimstart ttl +twgc +twgus typedef +typeparam UCase ucasemap UChars ucnv +udwgp uec ULONGLONG UNAVAIL @@ -564,6 +598,7 @@ URLZONE USEDEFAULT userfilesetting userprofile +uswgp uwp VALUENAMECASE vclib @@ -578,6 +613,7 @@ WDAG webpages Webserver website +websites wesome wfsopen wgetenv diff --git a/.github/actions/spelling/patterns.txt b/.github/actions/spelling/patterns.txt index e52a81ae81..04978c43ac 100644 --- a/.github/actions/spelling/patterns.txt +++ b/.github/actions/spelling/patterns.txt @@ -201,3 +201,6 @@ ReplaceWhileCopying\(L.*\) # devil fruits \s([A-Z]{3,}|[A-Z][a-z]{2,}|[a-z]{3,})\s\g{-1}\sno Mi + +# PowerShell Aliases defined in .cs files (not those in AliasesToExport in psd1 files) +\[Alias\("[a-z]+"\)\] diff --git a/src/PowerShell/Help/Microsoft.WinGet.Client/Disable-WinGetSetting.md b/src/PowerShell/Help/Microsoft.WinGet.Client/Disable-WinGetSetting.md index 4c78a1d9a3..25e9c436e1 100644 --- a/src/PowerShell/Help/Microsoft.WinGet.Client/Disable-WinGetSetting.md +++ b/src/PowerShell/Help/Microsoft.WinGet.Client/Disable-WinGetSetting.md @@ -81,6 +81,6 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## RELATED LINKS -[Get-WinGetSettings](Get-WinGetSettings.md) +[Get-WinGetSetting](Get-WinGetSetting.md) -[Set-WinGetUserSettings](Set-WinGetUserSettings.md) +[Set-WinGetUserSetting](Set-WinGetUserSetting.md) diff --git a/src/PowerShell/Help/Microsoft.WinGet.Client/Enable-WinGetSetting.md b/src/PowerShell/Help/Microsoft.WinGet.Client/Enable-WinGetSetting.md index d4b03f2b9e..d1dd09213f 100644 --- a/src/PowerShell/Help/Microsoft.WinGet.Client/Enable-WinGetSetting.md +++ b/src/PowerShell/Help/Microsoft.WinGet.Client/Enable-WinGetSetting.md @@ -82,6 +82,6 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## RELATED LINKS -[Get-WinGetSettings](Get-WinGetSettings.md) +[Get-WinGetSetting](Get-WinGetSetting.md) [Disable-WinGetSetting](Disable-WinGetSetting.md) diff --git a/src/PowerShell/Help/Microsoft.WinGet.Client/Get-WinGetSettings.md b/src/PowerShell/Help/Microsoft.WinGet.Client/Get-WinGetSetting.md similarity index 88% rename from src/PowerShell/Help/Microsoft.WinGet.Client/Get-WinGetSettings.md rename to src/PowerShell/Help/Microsoft.WinGet.Client/Get-WinGetSetting.md index 6c828f7b28..5f333f9b0d 100644 --- a/src/PowerShell/Help/Microsoft.WinGet.Client/Get-WinGetSettings.md +++ b/src/PowerShell/Help/Microsoft.WinGet.Client/Get-WinGetSetting.md @@ -4,10 +4,10 @@ Module Name: Microsoft.WinGet.Client ms.date: 08/01/2024 online version: schema: 2.0.0 -title: Get-WinGetSettings +title: Get-WinGetSetting --- -# Get-WinGetSettings +# Get-WinGetSetting ## SYNOPSIS Gets WinGet configuration settings. @@ -15,7 +15,7 @@ Gets WinGet configuration settings. ## SYNTAX ``` -Get-WinGetSettings [-AsPlainText] [] +Get-WinGetSetting [-AsPlainText] [] ``` ## DESCRIPTION @@ -32,7 +32,7 @@ For more information about WinGet settings, see ### Example 1 - Display the WinGet configuration settings ```powershell -Get-WinGetSettings +Get-WinGetSetting ``` ```Output @@ -47,7 +47,7 @@ adminSettings {[ProxyCommandLineOptions, False], [LocalArchiveMalwareScanOve ### Example 2 - Display the administrative settings in WinGet configuration ```powershell -Get-WinGetSettings | Select-Object -ExpandProperty adminSettings +Get-WinGetSetting | Select-Object -ExpandProperty adminSettings ``` ```Output @@ -97,6 +97,6 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## RELATED LINKS -[Get-WinGetUserSettings](Get-WinGetUserSettings.md) +[Get-WinGetUserSetting](Get-WinGetUserSetting.md) -[Set-WinGetUserSettings](Set-WinGetUserSettings.md) +[Set-WinGetUserSetting](Set-WinGetUserSetting.md) diff --git a/src/PowerShell/Help/Microsoft.WinGet.Client/Get-WinGetUserSettings.md b/src/PowerShell/Help/Microsoft.WinGet.Client/Get-WinGetUserSetting.md similarity index 79% rename from src/PowerShell/Help/Microsoft.WinGet.Client/Get-WinGetUserSettings.md rename to src/PowerShell/Help/Microsoft.WinGet.Client/Get-WinGetUserSetting.md index 9c6ef88b23..6cb4ade6d3 100644 --- a/src/PowerShell/Help/Microsoft.WinGet.Client/Get-WinGetUserSettings.md +++ b/src/PowerShell/Help/Microsoft.WinGet.Client/Get-WinGetUserSetting.md @@ -4,10 +4,10 @@ Module Name: Microsoft.WinGet.Client ms.date: 08/01/2024 online version: schema: 2.0.0 -title: Get-WinGetUserSettings +title: Get-WinGetUserSetting --- -# Get-WinGetUserSettings +# Get-WinGetUserSetting ## SYNOPSIS Gets user settings for WinGet. @@ -15,21 +15,21 @@ Gets user settings for WinGet. ## SYNTAX ``` -Get-WinGetUserSettings [] +Get-WinGetUserSetting [] ``` ## DESCRIPTION This command displays the WinGet settings for the current user. The settings are stored in `$env:LOCALAPPDATA\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json`. -This file only exists if you have changed a user setting, for example, using the `Set-WinGetUserSettings` command. +This file only exists if you have changed a user setting, for example, using the `Set-WinGetUserSetting` command. ## EXAMPLES ### Example 1: Get the WinGet settings for the current user ```powershell -Get-WinGetUserSettings +Get-WinGetUserSetting ``` ## PARAMETERS @@ -53,6 +53,6 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## RELATED LINKS -[Get-WinGetSettings](Get-WinGetSettings.md) +[Get-WinGetSetting](Get-WinGetSetting.md) -[Set-WinGetUserSettings](Set-WinGetUserSettings.md) +[Set-WinGetUserSetting](Set-WinGetUserSetting.md) diff --git a/src/PowerShell/Help/Microsoft.WinGet.Client/Microsoft.WinGet.Client.md b/src/PowerShell/Help/Microsoft.WinGet.Client/Microsoft.WinGet.Client.md index 44689febb5..c660a395a7 100644 --- a/src/PowerShell/Help/Microsoft.WinGet.Client/Microsoft.WinGet.Client.md +++ b/src/PowerShell/Help/Microsoft.WinGet.Client/Microsoft.WinGet.Client.md @@ -34,13 +34,13 @@ Searches configured sources for packages. ### [Get-WinGetPackage](Get-WinGetPackage.md) Gets installed packages. -### [Get-WinGetSettings](Get-WinGetSettings.md) +### [Get-WinGetSetting](Get-WinGetSetting.md) Gets WinGet settings. ### [Get-WinGetSource](Get-WinGetSource.md) Gets configured WinGet sources. -### [Get-WinGetUserSettings](Get-WinGetUserSettings.md) +### [Get-WinGetUserSetting](Get-WinGetUserSetting.md) Gets user settings for WinGet. ### [Get-WinGetVersion](Get-WinGetVersion.md) @@ -58,10 +58,10 @@ Repairs the WinGet client. ### [Reset-WinGetSource](Reset-WinGetSource.md) Resets default WinGet sources. -### [Set-WinGetUserSettings](Set-WinGetUserSettings.md) +### [Set-WinGetUserSetting](Set-WinGetUserSetting.md) Sets WinGet settings. -### [Test-WinGetUserSettings](Test-WinGetUserSettings.md) +### [Test-WinGetUserSetting](Test-WinGetUserSetting.md) Tests WinGet settings. ### [Uninstall-WinGetPackage](Uninstall-WinGetPackage.md) diff --git a/src/PowerShell/Help/Microsoft.WinGet.Client/Set-WinGetUserSettings.md b/src/PowerShell/Help/Microsoft.WinGet.Client/Set-WinGetUserSetting.md similarity index 87% rename from src/PowerShell/Help/Microsoft.WinGet.Client/Set-WinGetUserSettings.md rename to src/PowerShell/Help/Microsoft.WinGet.Client/Set-WinGetUserSetting.md index b76a7c4f4a..cba5723f38 100644 --- a/src/PowerShell/Help/Microsoft.WinGet.Client/Set-WinGetUserSettings.md +++ b/src/PowerShell/Help/Microsoft.WinGet.Client/Set-WinGetUserSetting.md @@ -4,10 +4,10 @@ Module Name: Microsoft.WinGet.Client ms.date: 08/01/2024 online version: schema: 2.0.0 -title: Set-WinGetUserSettings +title: Set-WinGetUserSetting --- -# Set-WinGetUserSettings +# Set-WinGetUserSetting ## SYNOPSIS Sets configuration settings of the WinGet client for the current user. @@ -15,7 +15,7 @@ Sets configuration settings of the WinGet client for the current user. ## SYNTAX ``` -Set-WinGetUserSettings -UserSettings [-Merge] [] +Set-WinGetUserSetting -UserSettings [-Merge] [] ``` ## DESCRIPTION @@ -31,7 +31,7 @@ For more information about WinGet settings, see ### Example 1: Set progress bar theme ```powershell -Set-WinGetUserSettings -UserSettings @{ +Set-WinGetUserSetting -UserSettings @{ visual = @{ progressBar = 'rainbow' } @@ -43,7 +43,7 @@ Sets the theme of the progress bar to rainbow. ### Example 2: Merge install behavior settings ```powershell -Set-WinGetUserSettings -Merge -UserSettings @{ +Set-WinGetUserSetting -Merge -UserSettings @{ installBehavior = @{ preferences = @{ scope = 'user' @@ -57,7 +57,7 @@ Appends the user scope preference setting to the existing WinGet settings config ### Example 3: Change multiple settings ```powershell -Set-WinGetUserSettings -UserSettings @{ +Set-WinGetUserSetting -UserSettings @{ visual = @{ progressBar = 'rainbow' anonymizeDisplayedPaths = $true @@ -121,6 +121,6 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## RELATED LINKS -[Get-WinGetUserSettings](Get-WinGetUserSettings.md) +[Get-WinGetUserSetting](Get-WinGetUserSetting.md) -[Test-WinGetUserSettings](Test-WinGetUserSettings.md) +[Test-WinGetUserSetting](Test-WinGetUserSetting.md) diff --git a/src/PowerShell/Help/Microsoft.WinGet.Client/Test-WinGetUserSettings.md b/src/PowerShell/Help/Microsoft.WinGet.Client/Test-WinGetUserSetting.md similarity index 86% rename from src/PowerShell/Help/Microsoft.WinGet.Client/Test-WinGetUserSettings.md rename to src/PowerShell/Help/Microsoft.WinGet.Client/Test-WinGetUserSetting.md index fbc0100c95..b90bebaf3f 100644 --- a/src/PowerShell/Help/Microsoft.WinGet.Client/Test-WinGetUserSettings.md +++ b/src/PowerShell/Help/Microsoft.WinGet.Client/Test-WinGetUserSetting.md @@ -4,10 +4,10 @@ Module Name: Microsoft.WinGet.Client ms.date: 08/01/2024 online version: schema: 2.0.0 -title: Test-WinGetUserSettings +title: Test-WinGetUserSetting --- -# Test-WinGetUserSettings +# Test-WinGetUserSetting ## SYNOPSIS Tests the current state of WinGet user settings. @@ -15,7 +15,7 @@ Tests the current state of WinGet user settings. ## SYNTAX ``` -Test-WinGetUserSettings -UserSettings [-IgnoreNotSet] [] +Test-WinGetUserSetting -UserSettings [-IgnoreNotSet] [] ``` ## DESCRIPTION @@ -27,7 +27,7 @@ This command tests the current state of WinGet user settings against a provided ### Example 1: Test for exact match ```powershell -Test-WinGetUserSettings -UserSettings @{ +Test-WinGetUserSetting -UserSettings @{ installBehavior = @{ preferences = @{ scope = 'user' @@ -42,7 +42,7 @@ command returns `$false` if it is not an exact match. ### Example 2: Test only progress bar setting ```powershell -Test-WinGetUserSettings -IgnoreNotSet -UserSettings @{ +Test-WinGetUserSetting -IgnoreNotSet -UserSettings @{ visual = @{ progressBar = 'rainbow' } @@ -109,6 +109,6 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## RELATED LINKS -[Get-WinGetUserSettings](Get-WinGetUserSettings.md) +[Get-WinGetUserSetting](Get-WinGetUserSetting.md) -[Set-WinGetUserSettings](Set-WinGetUserSettings.md) +[Set-WinGetUserSetting](Set-WinGetUserSetting.md) diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/AddSourceCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/AddSourceCmdlet.cs index 03a5e75793..51b00270ef 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/AddSourceCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/AddSourceCmdlet.cs @@ -15,6 +15,7 @@ namespace Microsoft.WinGet.Client.Cmdlets.Cmdlets /// Adds a source. Requires admin. /// [Cmdlet(VerbsCommon.Add, Constants.WinGetNouns.Source)] + [Alias("awgs")] public sealed class AddSourceCmdlet : PSCmdlet { /// diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/AssertWinGetPackageManagerCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/AssertWinGetPackageManagerCmdlet.cs index 9e574e1824..b33bdbd502 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/AssertWinGetPackageManagerCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/AssertWinGetPackageManagerCmdlet.cs @@ -18,6 +18,7 @@ namespace Microsoft.WinGet.Client.Commands VerbsLifecycle.Assert, Constants.WinGetNouns.WinGetPackageManager, DefaultParameterSetName = Constants.IntegrityVersionSet)] + [Alias("awgpm")] public class AssertWinGetPackageManagerCmdlet : WinGetPackageManagerCmdlet { /// diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/DisableSettingCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/DisableSettingCmdlet.cs index d2d3a42aa1..2ecaea93f1 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/DisableSettingCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/DisableSettingCmdlet.cs @@ -14,6 +14,7 @@ namespace Microsoft.WinGet.Client.Cmdlets.Cmdlets /// Disables an admin setting. Requires admin. /// [Cmdlet(VerbsLifecycle.Disable, Constants.WinGetNouns.Setting)] + [Alias("dwgs")] public sealed class DisableSettingCmdlet : PSCmdlet { /// diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/EnableSettingCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/EnableSettingCmdlet.cs index 039d08415c..80590ec353 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/EnableSettingCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/EnableSettingCmdlet.cs @@ -14,6 +14,7 @@ namespace Microsoft.WinGet.Client.Cmdlets.Cmdlets /// Enables an admin setting. Requires admin. /// [Cmdlet(VerbsLifecycle.Enable, Constants.WinGetNouns.Setting)] + [Alias("ewgs")] public sealed class EnableSettingCmdlet : PSCmdlet { /// diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/ExportPackageCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/ExportPackageCmdlet.cs index ac6c6929eb..6c012f682e 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/ExportPackageCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/ExportPackageCmdlet.cs @@ -1,39 +1,40 @@ -// ----------------------------------------------------------------------------- -// -// Copyright (c) Microsoft Corporation. Licensed under the MIT License. -// -// ----------------------------------------------------------------------------- - -namespace Microsoft.WinGet.Client.Commands -{ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGet.Client.Commands +{ using System.Management.Automation; - using Microsoft.WinGet.Client.Common; - using Microsoft.WinGet.Client.Engine.Commands; + using Microsoft.WinGet.Client.Common; + using Microsoft.WinGet.Client.Engine.Commands; using Microsoft.WinGet.Client.Engine.PSObjects; - /// - /// Downloads a package installer from the pipeline or from a configured source. - /// - [Cmdlet( - VerbsData.Export, - Constants.WinGetNouns.Package, - DefaultParameterSetName = Constants.FoundSet, - SupportsShouldProcess = true)] - [OutputType(typeof(PSDownloadResult))] - public sealed class ExportPackageCmdlet : InstallerSelectionCmdlet - { + /// + /// Downloads a package installer from the pipeline or from a configured source. + /// + [Cmdlet( + VerbsData.Export, + Constants.WinGetNouns.Package, + DefaultParameterSetName = Constants.FoundSet, + SupportsShouldProcess = true)] + [Alias("ewgp")] + [OutputType(typeof(PSDownloadResult))] + public sealed class ExportPackageCmdlet : InstallerSelectionCmdlet + { private DownloadCommand command = null; /// /// Gets or sets the directory where the installer will be downloaded to. - /// - [Parameter(ValueFromPipelineByPropertyName = true)] + /// + [Parameter(ValueFromPipelineByPropertyName = true)] public string DownloadDirectory { get; set; } - /// - /// Installs a package from the pipeline or from a configured source. - /// - protected override void ProcessRecord() + /// + /// Installs a package from the pipeline or from a configured source. + /// + protected override void ProcessRecord() { this.command = new DownloadCommand( this, @@ -47,7 +48,7 @@ protected override void ProcessRecord() this.AllowHashMismatch.ToBool(), this.SkipDependencies.ToBool(), this.Locale); - this.command.Download(this.DownloadDirectory, this.MatchOption.ToString(), this.Scope.ToString(), this.Architecture.ToString(), this.InstallerType.ToString()); + this.command.Download(this.DownloadDirectory, this.MatchOption.ToString(), this.Scope.ToString(), this.Architecture.ToString(), this.InstallerType.ToString()); } /// @@ -59,6 +60,6 @@ protected override void StopProcessing() { this.command.Cancel(); } - } - } -} + } + } +} diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/FindPackageCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/FindPackageCmdlet.cs index a16ac326a6..229fbe1831 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/FindPackageCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/FindPackageCmdlet.cs @@ -1,28 +1,29 @@ -// ----------------------------------------------------------------------------- -// -// Copyright (c) Microsoft Corporation. Licensed under the MIT License. -// -// ----------------------------------------------------------------------------- - -namespace Microsoft.WinGet.Client.Commands -{ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGet.Client.Commands +{ using System.Management.Automation; - using Microsoft.WinGet.Client.Commands.Common; + using Microsoft.WinGet.Client.Commands.Common; using Microsoft.WinGet.Client.Common; using Microsoft.WinGet.Client.Engine.Commands; - using Microsoft.WinGet.Client.Engine.PSObjects; - - /// - /// Searches configured sources for packages. - /// - [Cmdlet(VerbsCommon.Find, Constants.WinGetNouns.Package)] - [OutputType(typeof(PSFoundCatalogPackage))] - public sealed class FindPackageCmdlet : FinderExtendedCmdlet - { - /// - /// Searches for configured sources for packages. - /// - protected override void ProcessRecord() + using Microsoft.WinGet.Client.Engine.PSObjects; + + /// + /// Searches configured sources for packages. + /// + [Cmdlet(VerbsCommon.Find, Constants.WinGetNouns.Package)] + [Alias("fdwgp")] + [OutputType(typeof(PSFoundCatalogPackage))] + public sealed class FindPackageCmdlet : FinderExtendedCmdlet + { + /// + /// Searches for configured sources for packages. + /// + protected override void ProcessRecord() { var command = new FinderPackageCommand( this, @@ -35,7 +36,7 @@ protected override void ProcessRecord() this.Command, this.Count); - command.Find(this.MatchOption.ToString()); - } - } -} + command.Find(this.MatchOption.ToString()); + } + } +} diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetPackageCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetPackageCmdlet.cs index 01fab7ccdd..9338faba32 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetPackageCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetPackageCmdlet.cs @@ -16,6 +16,7 @@ namespace Microsoft.WinGet.Client.Commands /// Searches configured sources for packages. /// [Cmdlet(VerbsCommon.Get, Constants.WinGetNouns.Package)] + [Alias("gwgp")] [OutputType(typeof(PSInstalledCatalogPackage))] public sealed class GetPackageCmdlet : FinderExtendedCmdlet { diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetSettingsCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetSettingCmdlet.cs similarity index 75% rename from src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetSettingsCmdlet.cs rename to src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetSettingCmdlet.cs index 6aacade5a2..39067d11d1 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetSettingsCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetSettingCmdlet.cs @@ -1,34 +1,35 @@ -// ----------------------------------------------------------------------------- -// -// Copyright (c) Microsoft Corporation. Licensed under the MIT License. -// -// ----------------------------------------------------------------------------- - -namespace Microsoft.WinGet.Client.Cmdlets.Cmdlets -{ - using System.Management.Automation; - using Microsoft.WinGet.Client.Common; - using Microsoft.WinGet.Client.Engine.Commands; - - /// - /// Gets winget settings. - /// - [Cmdlet(VerbsCommon.Get, Constants.WinGetNouns.Settings)] - public sealed class GetSettingsCmdlet : PSCmdlet - { - /// - /// Gets or sets a value indicating whether to output a string or a hashtable. - /// - [Parameter(ValueFromPipelineByPropertyName = true)] - public SwitchParameter AsPlainText { get; set; } - - /// - /// Get settings. - /// - protected override void ProcessRecord() - { - var command = new CliCommand(this); - command.GetSettings(this.AsPlainText.ToBool()); - } - } -} +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGet.Client.Cmdlets.Cmdlets +{ + using System.Management.Automation; + using Microsoft.WinGet.Client.Common; + using Microsoft.WinGet.Client.Engine.Commands; + + /// + /// Gets winget settings. + /// + [Cmdlet(VerbsCommon.Get, Constants.WinGetNouns.Setting)] + [Alias("gwgse", "Get-WinGetSettings")] + public sealed class GetSettingCmdlet : PSCmdlet + { + /// + /// Gets or sets a value indicating whether to output a string or a hashtable. + /// + [Parameter(ValueFromPipelineByPropertyName = true)] + public SwitchParameter AsPlainText { get; set; } + + /// + /// Get settings. + /// + protected override void ProcessRecord() + { + var command = new CliCommand(this); + command.GetSettings(this.AsPlainText.ToBool()); + } + } +} diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetSourceCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetSourceCmdlet.cs index 4674456dfc..f19ee12f6a 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetSourceCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetSourceCmdlet.cs @@ -1,39 +1,40 @@ -// ----------------------------------------------------------------------------- -// -// Copyright (c) Microsoft Corporation. Licensed under the MIT License. -// -// ----------------------------------------------------------------------------- - -namespace Microsoft.WinGet.Client.Commands -{ - using System.Management.Automation; +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGet.Client.Commands +{ + using System.Management.Automation; using Microsoft.WinGet.Client.Common; using Microsoft.WinGet.Client.Engine.Commands; using Microsoft.WinGet.Client.Engine.PSObjects; - /// - /// Retrieves the list of configured sources. - /// - [Cmdlet(VerbsCommon.Get, Constants.WinGetNouns.Source)] - [OutputType(typeof(PSSourceResult))] - public sealed class GetSourceCmdlet : PSCmdlet - { - /// - /// Gets or sets the name of the source to retrieve. - /// - [Parameter( - Position = 0, - ValueFromPipeline = true, - ValueFromPipelineByPropertyName = true)] - public string Name { get; set; } - - /// - /// Returns the list of configured sources. - /// - protected override void ProcessRecord() - { - var command = new SourceCommand(this); - command.Get(this.Name); - } - } -} + /// + /// Retrieves the list of configured sources. + /// + [Cmdlet(VerbsCommon.Get, Constants.WinGetNouns.Source)] + [Alias("gwgso")] + [OutputType(typeof(PSSourceResult))] + public sealed class GetSourceCmdlet : PSCmdlet + { + /// + /// Gets or sets the name of the source to retrieve. + /// + [Parameter( + Position = 0, + ValueFromPipeline = true, + ValueFromPipelineByPropertyName = true)] + public string Name { get; set; } + + /// + /// Returns the list of configured sources. + /// + protected override void ProcessRecord() + { + var command = new SourceCommand(this); + command.Get(this.Name); + } + } +} diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetUserSettingsCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetUserSettingCmdlet.cs similarity index 77% rename from src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetUserSettingsCmdlet.cs rename to src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetUserSettingCmdlet.cs index 200ef1b8b6..fe9dcdefef 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetUserSettingsCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetUserSettingCmdlet.cs @@ -1,30 +1,31 @@ -// ----------------------------------------------------------------------------- -// -// Copyright (c) Microsoft Corporation. Licensed under the MIT License. -// -// ----------------------------------------------------------------------------- - -namespace Microsoft.WinGet.Client.Commands -{ - using System.Collections; - using System.Management.Automation; - using Microsoft.WinGet.Client.Common; - using Microsoft.WinGet.Client.Engine.Commands; - - /// - /// Gets winget's user settings. - /// - [Cmdlet(VerbsCommon.Get, Constants.WinGetNouns.UserSettings)] - [OutputType(typeof(Hashtable))] - public sealed class GetUserSettingsCmdlet : PSCmdlet - { - /// - /// Gets the settings file contents. - /// - protected override void ProcessRecord() - { - var command = new UserSettingsCommand(this); - command.Get(); - } - } -} +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGet.Client.Commands +{ + using System.Collections; + using System.Management.Automation; + using Microsoft.WinGet.Client.Common; + using Microsoft.WinGet.Client.Engine.Commands; + + /// + /// Gets winget's user settings. + /// + [Cmdlet(VerbsCommon.Get, Constants.WinGetNouns.UserSetting)] + [Alias("gwgus", "Get-WinGetUserSettings")] + [OutputType(typeof(Hashtable))] + public sealed class GetUserSettingCmdlet : PSCmdlet + { + /// + /// Gets the settings file contents. + /// + protected override void ProcessRecord() + { + var command = new UserSettingsCommand(this); + command.Get(); + } + } +} diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetVersionCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetVersionCmdlet.cs index 89c32e5ce7..c15cdbe5d2 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetVersionCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetVersionCmdlet.cs @@ -14,6 +14,7 @@ namespace Microsoft.WinGet.Client.Commands /// Get-WinGetVersion. Gets the current version of winget. /// [Cmdlet(VerbsCommon.Get, Constants.WinGetNouns.Version)] + [Alias("gwgv")] [OutputType(typeof(string))] public class GetVersionCmdlet : PSCmdlet { diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/InstallPackageCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/InstallPackageCmdlet.cs index b5d07718ed..968319e891 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/InstallPackageCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/InstallPackageCmdlet.cs @@ -20,6 +20,7 @@ namespace Microsoft.WinGet.Client.Commands Constants.WinGetNouns.Package, DefaultParameterSetName = Constants.FoundSet, SupportsShouldProcess = true)] + [Alias("iswgp")] [OutputType(typeof(PSInstallResult))] public sealed class InstallPackageCmdlet : InstallCmdlet { diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/RemoveSourceCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/RemoveSourceCmdlet.cs index 863620a7cb..cf30a7d016 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/RemoveSourceCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/RemoveSourceCmdlet.cs @@ -14,6 +14,7 @@ namespace Microsoft.WinGet.Client.Cmdlets /// Removes a source. Requires admin. /// [Cmdlet(VerbsCommon.Remove, Constants.WinGetNouns.Source)] + [Alias("rwgs")] public sealed class RemoveSourceCmdlet : PSCmdlet { /// diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/RepairWinGetPackageManagerCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/RepairWinGetPackageManagerCmdlet.cs index 71b8a0f7a9..b3e6ae4df2 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/RepairWinGetPackageManagerCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/RepairWinGetPackageManagerCmdlet.cs @@ -18,6 +18,7 @@ namespace Microsoft.WinGet.Client.Commands VerbsDiagnostic.Repair, Constants.WinGetNouns.WinGetPackageManager, DefaultParameterSetName = Constants.IntegrityVersionSet)] + [Alias("rpwgpm")] [OutputType(typeof(int))] public class RepairWinGetPackageManagerCmdlet : WinGetPackageManagerCmdlet { diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/ResetSourceCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/ResetSourceCmdlet.cs index be667df2f8..1dfdcee6ad 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/ResetSourceCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/ResetSourceCmdlet.cs @@ -14,6 +14,7 @@ namespace Microsoft.WinGet.Client.Cmdlets.Cmdlets /// Resets a source. Requires admin. /// [Cmdlet(VerbsCommon.Reset, Constants.WinGetNouns.Source, DefaultParameterSetName = Constants.DefaultSet)] + [Alias("rswgs")] public sealed class ResetSourceCmdlet : PSCmdlet { /// diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/SetUserSettingsCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/SetUserSettingCmdlet.cs similarity index 86% rename from src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/SetUserSettingsCmdlet.cs rename to src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/SetUserSettingCmdlet.cs index 0a3f8e9178..12a0764dff 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/SetUserSettingsCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/SetUserSettingCmdlet.cs @@ -1,45 +1,46 @@ -// ----------------------------------------------------------------------------- -// -// Copyright (c) Microsoft Corporation. Licensed under the MIT License. -// -// ----------------------------------------------------------------------------- - -namespace Microsoft.WinGet.Client.Commands -{ - using System.Collections; - using System.Management.Automation; - using Microsoft.WinGet.Client.Common; - using Microsoft.WinGet.Client.Engine.Commands; - - /// - /// Sets the specified user settings into the winget user settings. If the merge switch is on, merges current user - /// settings with the input settings. Otherwise, overwrites the input settings. - /// - [Cmdlet(VerbsCommon.Set, Constants.WinGetNouns.UserSettings)] - [OutputType(typeof(Hashtable))] - public sealed class SetUserSettingsCmdlet : PSCmdlet - { - /// - /// Gets or sets the input user settings. - /// - [Parameter( - Mandatory = true, - ValueFromPipelineByPropertyName = true)] - public Hashtable UserSettings { get; set; } - - /// - /// Gets or sets a value indicating whether to merge the current user settings and the input settings. - /// - [Parameter(ValueFromPipelineByPropertyName = true)] - public SwitchParameter Merge { get; set; } - - /// - /// Process input of cmdlet. - /// - protected override void ProcessRecord() - { - var command = new UserSettingsCommand(this); - command.Set(this.UserSettings, this.Merge.ToBool()); - } - } -} +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGet.Client.Commands +{ + using System.Collections; + using System.Management.Automation; + using Microsoft.WinGet.Client.Common; + using Microsoft.WinGet.Client.Engine.Commands; + + /// + /// Sets the specified user settings into the winget user settings. If the merge switch is on, merges current user + /// settings with the input settings. Otherwise, overwrites the input settings. + /// + [Cmdlet(VerbsCommon.Set, Constants.WinGetNouns.UserSetting)] + [Alias("swgus", "Set-WinGetUserSettings")] + [OutputType(typeof(Hashtable))] + public sealed class SetUserSettingCmdlet : PSCmdlet + { + /// + /// Gets or sets the input user settings. + /// + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + public Hashtable UserSettings { get; set; } + + /// + /// Gets or sets a value indicating whether to merge the current user settings and the input settings. + /// + [Parameter(ValueFromPipelineByPropertyName = true)] + public SwitchParameter Merge { get; set; } + + /// + /// Process input of cmdlet. + /// + protected override void ProcessRecord() + { + var command = new UserSettingsCommand(this); + command.Set(this.UserSettings, this.Merge.ToBool()); + } + } +} diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/TestUserSettingsCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/TestUserSettingCmdlet.cs similarity index 88% rename from src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/TestUserSettingsCmdlet.cs rename to src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/TestUserSettingCmdlet.cs index d938ff9312..8a9bf4910f 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/TestUserSettingsCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/TestUserSettingCmdlet.cs @@ -1,44 +1,45 @@ -// ----------------------------------------------------------------------------- -// -// Copyright (c) Microsoft Corporation. Licensed under the MIT License. -// -// ----------------------------------------------------------------------------- - -namespace Microsoft.WinGet.Client.Commands -{ - using System.Collections; - using System.Management.Automation; - using Microsoft.WinGet.Client.Common; - using Microsoft.WinGet.Client.Engine.Commands; - - /// - /// Compare the specified user settings with the winget user settings. - /// - [Cmdlet(VerbsDiagnostic.Test, Constants.WinGetNouns.UserSettings)] - [OutputType(typeof(bool))] - public sealed class TestUserSettingsCmdlet : PSCmdlet - { - /// - /// Gets or sets the input user settings. - /// - [Parameter( - Mandatory = true, - ValueFromPipelineByPropertyName = true)] - public Hashtable UserSettings { get; set; } - - /// - /// Gets or sets a value indicating whether to ignore comparing settings that are not part of the input. - /// - [Parameter(ValueFromPipelineByPropertyName = true)] - public SwitchParameter IgnoreNotSet { get; set; } - - /// - /// Process the cmdlet and writes the result of the comparison. - /// - protected override void ProcessRecord() - { - var command = new UserSettingsCommand(this); - command.Test(this.UserSettings, this.IgnoreNotSet.ToBool()); - } - } -} +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGet.Client.Commands +{ + using System.Collections; + using System.Management.Automation; + using Microsoft.WinGet.Client.Common; + using Microsoft.WinGet.Client.Engine.Commands; + + /// + /// Compare the specified user settings with the winget user settings. + /// + [Cmdlet(VerbsDiagnostic.Test, Constants.WinGetNouns.UserSetting)] + [Alias("twgus", "Test-WinGetUserSettings")] + [OutputType(typeof(bool))] + public sealed class TestUserSettingCmdlet : PSCmdlet + { + /// + /// Gets or sets the input user settings. + /// + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + public Hashtable UserSettings { get; set; } + + /// + /// Gets or sets a value indicating whether to ignore comparing settings that are not part of the input. + /// + [Parameter(ValueFromPipelineByPropertyName = true)] + public SwitchParameter IgnoreNotSet { get; set; } + + /// + /// Process the cmdlet and writes the result of the comparison. + /// + protected override void ProcessRecord() + { + var command = new UserSettingsCommand(this); + command.Test(this.UserSettings, this.IgnoreNotSet.ToBool()); + } + } +} diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/UninstallPackageCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/UninstallPackageCmdlet.cs index f2b93beecf..46518a7d2d 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/UninstallPackageCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/UninstallPackageCmdlet.cs @@ -1,53 +1,54 @@ -// ----------------------------------------------------------------------------- -// -// Copyright (c) Microsoft Corporation. Licensed under the MIT License. -// -// ----------------------------------------------------------------------------- - -namespace Microsoft.WinGet.Client.Commands -{ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGet.Client.Commands +{ using System.Management.Automation; - using Microsoft.WinGet.Client.Commands.Common; - using Microsoft.WinGet.Client.Common; - using Microsoft.WinGet.Client.Engine.Commands; + using Microsoft.WinGet.Client.Commands.Common; + using Microsoft.WinGet.Client.Common; + using Microsoft.WinGet.Client.Engine.Commands; using Microsoft.WinGet.Client.Engine.PSObjects; using Microsoft.WinGet.Client.PSObjects; - /// - /// Uninstalls a package from the local system. - /// - [Cmdlet( - VerbsLifecycle.Uninstall, - Constants.WinGetNouns.Package, - DefaultParameterSetName = Constants.FoundSet, - SupportsShouldProcess = true)] - [OutputType(typeof(PSUninstallResult))] - public sealed class UninstallPackageCmdlet : PackageCmdlet - { - private UninstallPackageCommand command = null; - - /// - /// Gets or sets the desired mode for the uninstallation process. - /// - [Parameter(ValueFromPipelineByPropertyName = true)] - public PSPackageUninstallMode Mode { get; set; } = PSPackageUninstallMode.Default; - - /// - /// Gets or sets a value indicating whether to continue upon non security related failures. - /// - [Parameter(ValueFromPipelineByPropertyName = true)] + /// + /// Uninstalls a package from the local system. + /// + [Cmdlet( + VerbsLifecycle.Uninstall, + Constants.WinGetNouns.Package, + DefaultParameterSetName = Constants.FoundSet, + SupportsShouldProcess = true)] + [Alias("uswgp")] + [OutputType(typeof(PSUninstallResult))] + public sealed class UninstallPackageCmdlet : PackageCmdlet + { + private UninstallPackageCommand command = null; + + /// + /// Gets or sets the desired mode for the uninstallation process. + /// + [Parameter(ValueFromPipelineByPropertyName = true)] + public PSPackageUninstallMode Mode { get; set; } = PSPackageUninstallMode.Default; + + /// + /// Gets or sets a value indicating whether to continue upon non security related failures. + /// + [Parameter(ValueFromPipelineByPropertyName = true)] public SwitchParameter Force { get; set; } - /// - /// Gets or sets the path to the logging file. - /// - [Parameter(ValueFromPipelineByPropertyName = true)] - public string Log { get; set; } - - /// - /// Uninstalls a package from the local system. - /// - protected override void ProcessRecord() + /// + /// Gets or sets the path to the logging file. + /// + [Parameter(ValueFromPipelineByPropertyName = true)] + public string Log { get; set; } + + /// + /// Uninstalls a package from the local system. + /// + protected override void ProcessRecord() { this.command = new UninstallPackageCommand( this, @@ -59,7 +60,7 @@ protected override void ProcessRecord() this.Moniker, this.Source, this.Query); - this.command.Uninstall(this.MatchOption.ToString(), this.Mode.ToString(), this.Force.ToBool()); + this.command.Uninstall(this.MatchOption.ToString(), this.Mode.ToString(), this.Force.ToBool()); } /// @@ -71,6 +72,6 @@ protected override void StopProcessing() { this.command.Cancel(); } - } - } -} + } + } +} diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/UpdatePackageCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/UpdatePackageCmdlet.cs index 2dcc785975..bdcf9832d3 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/UpdatePackageCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/UpdatePackageCmdlet.cs @@ -1,38 +1,39 @@ -// ----------------------------------------------------------------------------- -// -// Copyright (c) Microsoft Corporation. Licensed under the MIT License. -// -// ----------------------------------------------------------------------------- - -namespace Microsoft.WinGet.Client.Commands -{ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGet.Client.Commands +{ using System.Management.Automation; using Microsoft.WinGet.Client.Commands.Common; using Microsoft.WinGet.Client.Common; using Microsoft.WinGet.Client.Engine.Commands; using Microsoft.WinGet.Client.Engine.PSObjects; - /// - /// This commands updates a package from the pipeline or from the local system. - /// - [Cmdlet( - VerbsData.Update, - Constants.WinGetNouns.Package, - DefaultParameterSetName = Constants.FoundSet, - SupportsShouldProcess = true)] - [OutputType(typeof(PSInstallResult))] - public sealed class UpdatePackageCmdlet : InstallCmdlet - { - /// - /// Gets or sets a value indicating whether updating to an unknown version is allowed. - /// - [Parameter(ValueFromPipelineByPropertyName = true)] - public SwitchParameter IncludeUnknown { get; set; } - - /// - /// Updates a package from the pipeline or from the local system. - /// - protected override void ProcessRecord() + /// + /// This commands updates a package from the pipeline or from the local system. + /// + [Cmdlet( + VerbsData.Update, + Constants.WinGetNouns.Package, + DefaultParameterSetName = Constants.FoundSet, + SupportsShouldProcess = true)] + [Alias("udwgp")] + [OutputType(typeof(PSInstallResult))] + public sealed class UpdatePackageCmdlet : InstallCmdlet + { + /// + /// Gets or sets a value indicating whether updating to an unknown version is allowed. + /// + [Parameter(ValueFromPipelineByPropertyName = true)] + public SwitchParameter IncludeUnknown { get; set; } + + /// + /// Updates a package from the pipeline or from the local system. + /// + protected override void ProcessRecord() { var command = new InstallerPackageCommand( this, @@ -51,7 +52,7 @@ protected override void ProcessRecord() this.Source, this.Query, this.SkipDependencies); - command.Update(this.IncludeUnknown.ToBool(), this.MatchOption.ToString(), this.Scope.ToString(), this.Architecture.ToString(), this.Mode.ToString(), this.InstallerType.ToString()); - } - } -} + command.Update(this.IncludeUnknown.ToBool(), this.MatchOption.ToString(), this.Scope.ToString(), this.Architecture.ToString(), this.Mode.ToString(), this.InstallerType.ToString()); + } + } +} diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Common/Constants.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Common/Constants.cs index 0f403a512f..62847c6567 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Common/Constants.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Common/Constants.cs @@ -75,22 +75,17 @@ public static class WinGetNouns /// /// The noun for any user settings cmdlet. /// - public const string UserSettings = "WinGetUserSettings"; + public const string UserSetting = "WinGetUserSetting"; /// /// The noun for winget version. /// public const string Version = "WinGetVersion"; - /// - /// The noun for enable/disable winget admin settings. + /// + /// The noun for enable/disable winget admin settings. /// public const string Setting = "WinGetSetting"; - - /// - /// The noun to get the winget settings. - /// - public const string Settings = "WinGetSettings"; } } } diff --git a/src/PowerShell/Microsoft.WinGet.Client.Engine/Commands/UserSettingsCommand.cs b/src/PowerShell/Microsoft.WinGet.Client.Engine/Commands/UserSettingsCommand.cs index 0c82256120..64433e0b6c 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Engine/Commands/UserSettingsCommand.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Engine/Commands/UserSettingsCommand.cs @@ -51,7 +51,7 @@ public UserSettingsCommand(PSCmdlet psCmdlet) } /// - /// Get-WinGetUserSettings. + /// Get-WinGetUserSetting. /// public void Get() { @@ -59,7 +59,7 @@ public void Get() } /// - /// Test-WinGetUserSettings. + /// Test-WinGetUserSetting. /// /// Input user settings. /// Ignore comparing settings that are not part of the input. @@ -69,7 +69,7 @@ public void Test(Hashtable userSettings, bool ignoreNotSet) } /// - /// Set-WinGetUserSettings. + /// Set-WinGetUserSetting. /// /// Input user settings. /// Merge the current user settings and the input settings. diff --git a/src/PowerShell/Microsoft.WinGet.Client/ModuleFiles/Microsoft.WinGet.Client.psd1 b/src/PowerShell/Microsoft.WinGet.Client/ModuleFiles/Microsoft.WinGet.Client.psd1 index c0f3786ee1..852e6aec8d 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/ModuleFiles/Microsoft.WinGet.Client.psd1 +++ b/src/PowerShell/Microsoft.WinGet.Client/ModuleFiles/Microsoft.WinGet.Client.psd1 @@ -82,14 +82,14 @@ CmdletsToExport = @( 'Install-WinGetPackage' 'Uninstall-WinGetPackage' 'Update-WinGetPackage' - 'Get-WinGetUserSettings' - 'Set-WinGetUserSettings' - 'Test-WinGetUserSettings' + 'Get-WinGetUserSetting' + 'Set-WinGetUserSetting' + 'Test-WinGetUserSetting' 'Assert-WinGetPackageManager' 'Repair-WinGetPackageManager' 'Enable-WinGetSetting' 'Disable-WinGetSetting' - 'Get-WinGetSettings' + 'Get-WinGetSetting' 'Add-WinGetSource' 'Remove-WinGetSource' 'Reset-WinGetSource' @@ -100,7 +100,29 @@ CmdletsToExport = @( # VariablesToExport = @() # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. -AliasesToExport = @() + AliasesToExport = @('awgs' + 'awgpm' + 'dwgs' + 'ewgs' + 'ewgp' + 'fdwgp' + 'gwgp' + 'gwgse' + 'gwgso' + 'gwgus' + 'gwgv' + 'iswgp' + 'rwgs' + 'rpwgpm' + 'rswgs' + 'swgus' + 'twgus' + 'uswgp' + 'udwgp', + 'Get-WinGetSettings' + 'Get-WinGetUserSettings' + 'Set-WinGetUserSettings' + 'Test-WinGetUserSettings') # DSC resources to export from this module # DscResourcesToExport = @() diff --git a/src/PowerShell/Microsoft.WinGet.Client/README.md b/src/PowerShell/Microsoft.WinGet.Client/README.md index 538afd1814..00f3d4ece3 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/README.md +++ b/src/PowerShell/Microsoft.WinGet.Client/README.md @@ -27,18 +27,18 @@ If the new cmdlet introduces a new dependency, please make sure to add it in the - Find-WinGetPackage - Get-WinGetPackage - Get-WinGetSource -- Get-WinGetUserSettings +- Get-WinGetUserSetting - Get-WinGetVersion - Install-WinGetPackage - Repair-WinGetPackageManager -- Set-WinGetUserSettings -- Test-WinGetUserSettings +- Set-WinGetUserSetting +- Test-WinGetUserSetting - Uninstall-WinGetPackage - Update-WinGetPackage - Add-WinGetSource - Disable-WinGetSetting - Enable-WinGetSetting -- Get-WinGetSettings +- Get-WinGetSetting - Remove-WinGetSource - Reset-WinGetSource diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/CompleteWinGetConfigurationCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/CompleteWinGetConfigurationCmdlet.cs index e647279413..2fdb31c849 100644 --- a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/CompleteWinGetConfigurationCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/CompleteWinGetConfigurationCmdlet.cs @@ -16,6 +16,7 @@ namespace Microsoft.WinGet.Configuration.Cmdlets /// Waits for completion. /// [Cmdlet(VerbsLifecycle.Complete, "WinGetConfiguration")] + [Alias("cmpwgc")] public sealed class CompleteWinGetConfigurationCmdlet : PSCmdlet { private ConfigurationCommand runningCommand = null; diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/ConfirmWinGetConfigurationCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/ConfirmWinGetConfigurationCmdlet.cs index d7b5fb2147..72df06d19a 100644 --- a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/ConfirmWinGetConfigurationCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/ConfirmWinGetConfigurationCmdlet.cs @@ -15,6 +15,7 @@ namespace Microsoft.WinGet.Configuration.Cmdlets /// Validates winget configuration. /// [Cmdlet(VerbsLifecycle.Confirm, "WinGetConfiguration")] + [Alias("cnwgc")] public class ConfirmWinGetConfigurationCmdlet : PSCmdlet { private ConfigurationCommand runningCommand = null; diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/ConvertToWinGetConfigurationYamlCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/ConvertToWinGetConfigurationYamlCmdlet.cs index fbe0d65804..615075190d 100644 --- a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/ConvertToWinGetConfigurationYamlCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/ConvertToWinGetConfigurationYamlCmdlet.cs @@ -15,6 +15,7 @@ namespace Microsoft.WinGet.Configuration.Cmdlets /// Serializes a PSConfigurationSet to a YAML string. /// [Cmdlet(VerbsData.ConvertTo, "WinGetConfigurationYaml")] + [Alias("ctwgcy")] public sealed class ConvertToWinGetConfigurationYamlCmdlet : PSCmdlet { /// diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/GetWinGetConfigurationCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/GetWinGetConfigurationCmdlet.cs index 03cf4162a9..39f9a914a0 100644 --- a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/GetWinGetConfigurationCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/GetWinGetConfigurationCmdlet.cs @@ -15,6 +15,7 @@ namespace Microsoft.WinGet.Configuration.Cmdlets /// Opens a configuration set. /// [Cmdlet(VerbsCommon.Get, "WinGetConfiguration", DefaultParameterSetName = Helpers.Constants.ParameterSet.OpenConfigurationSetFromFile)] + [Alias("gwgc")] public sealed class GetWinGetConfigurationCmdlet : OpenConfiguration { /// diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/GetWinGetConfigurationDetailsCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/GetWinGetConfigurationDetailsCmdlet.cs index ec4b94fe82..a567637210 100644 --- a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/GetWinGetConfigurationDetailsCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/GetWinGetConfigurationDetailsCmdlet.cs @@ -16,6 +16,7 @@ namespace Microsoft.WinGet.Configuration.Cmdlets /// Gets the details for the units in a configuration set. /// [Cmdlet(VerbsCommon.Get, "WinGetConfigurationDetails")] + [Alias("gwgcd")] public sealed class GetWinGetConfigurationDetailsCmdlet : PSCmdlet { private ConfigurationCommand runningCommand = null; diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/InvokeWinGetConfigurationCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/InvokeWinGetConfigurationCmdlet.cs index b22f07eb4b..1db374fea2 100644 --- a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/InvokeWinGetConfigurationCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/InvokeWinGetConfigurationCmdlet.cs @@ -17,6 +17,7 @@ namespace Microsoft.WinGet.Configuration.Cmdlets /// Wait for completion. /// [Cmdlet(VerbsLifecycle.Invoke, "WinGetConfiguration")] + [Alias("iwgc")] public sealed class InvokeWinGetConfigurationCmdlet : PSCmdlet { private bool acceptedAgreements = false; diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/RemoveWinGetConfigurationHistoryCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/RemoveWinGetConfigurationHistoryCmdlet.cs index 5d12307af0..7f69b91aaa 100644 --- a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/RemoveWinGetConfigurationHistoryCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/RemoveWinGetConfigurationHistoryCmdlet.cs @@ -15,6 +15,7 @@ namespace Microsoft.WinGet.Configuration.Cmdlets /// Removes the given configuration set from history. /// [Cmdlet(VerbsCommon.Remove, "WinGetConfigurationHistory")] + [Alias("rwgch")] public sealed class RemoveWinGetConfigurationHistoryCmdlet : PSCmdlet { /// diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/StartWinGetConfigurationCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/StartWinGetConfigurationCmdlet.cs index 2e40575611..494cfc66d7 100644 --- a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/StartWinGetConfigurationCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/StartWinGetConfigurationCmdlet.cs @@ -16,6 +16,7 @@ namespace Microsoft.WinGet.Configuration.Cmdlets /// Does not wait for completion. /// [Cmdlet(VerbsLifecycle.Start, "WinGetConfiguration")] + [Alias("sawgc")] public sealed class StartWinGetConfigurationCmdlet : PSCmdlet { private bool acceptedAgreements = false; diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/StopWinGetConfigurationCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/StopWinGetConfigurationCmdlet.cs index 5b59cc44f0..da367b4fa2 100644 --- a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/StopWinGetConfigurationCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/StopWinGetConfigurationCmdlet.cs @@ -15,6 +15,7 @@ namespace Microsoft.WinGet.Configuration.Cmdlets /// Cancels a configuration previously started by Start-WinGetConfiguration. /// [Cmdlet(VerbsLifecycle.Stop, "WinGetConfiguration")] + [Alias("spwgc")] public sealed class StopWinGetConfigurationCmdlet : PSCmdlet { /// diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/TestWinGetConfigurationCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/TestWinGetConfigurationCmdlet.cs index 8aaab94f15..772c132320 100644 --- a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/TestWinGetConfigurationCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/TestWinGetConfigurationCmdlet.cs @@ -15,6 +15,7 @@ namespace Microsoft.WinGet.Configuration.Cmdlets /// Tests configuration. /// [Cmdlet(VerbsDiagnostic.Test, "WinGetConfiguration")] + [Alias("twgc")] public class TestWinGetConfigurationCmdlet : PSCmdlet { private bool acceptedAgreements = false; diff --git a/src/PowerShell/Microsoft.WinGet.Configuration/ModuleFiles/Microsoft.WinGet.Configuration.psd1 b/src/PowerShell/Microsoft.WinGet.Configuration/ModuleFiles/Microsoft.WinGet.Configuration.psd1 index c6a0a016fd..299a0123b9 100644 --- a/src/PowerShell/Microsoft.WinGet.Configuration/ModuleFiles/Microsoft.WinGet.Configuration.psd1 +++ b/src/PowerShell/Microsoft.WinGet.Configuration/ModuleFiles/Microsoft.WinGet.Configuration.psd1 @@ -10,7 +10,7 @@ PowerShellVersion = '7.2.8' FunctionsToExport = @() - AliasesToExport = @() + AliasesToExport = @('cmpwgc', 'cnwgc', 'ctwgcy', 'gwgc', 'gwgcd', 'iwgc', 'rwgch', 'sawgc', 'spwgc','twgc') CmdletsToExport = @( "Complete-WinGetConfiguration" diff --git a/src/PowerShell/Microsoft.WinGet.DSC/Microsoft.WinGet.DSC.psm1 b/src/PowerShell/Microsoft.WinGet.DSC/Microsoft.WinGet.DSC.psm1 index f6e7602a2b..749cc9d608 100644 --- a/src/PowerShell/Microsoft.WinGet.DSC/Microsoft.WinGet.DSC.psm1 +++ b/src/PowerShell/Microsoft.WinGet.DSC/Microsoft.WinGet.DSC.psm1 @@ -74,9 +74,9 @@ class WinGetUserSettings # Gets the current UserSettings by looking at the settings.json file for the current user. [WinGetUserSettings] Get() { - Assert-WinGetCommand "Get-WinGetUserSettings" + Assert-WinGetCommand "Get-WinGetUserSetting" - $userSettings = Get-WinGetUserSettings + $userSettings = Get-WinGetUserSetting $result = @{ SID = '' Settings = $userSettings @@ -87,7 +87,7 @@ class WinGetUserSettings # Tests if desired properties match. [bool] Test() { - Assert-WinGetCommand "Test-WinGetUserSettings" + Assert-WinGetCommand "Test-WinGetUserSetting" $hashArgs = @{ UserSettings = $this.Settings @@ -98,13 +98,13 @@ class WinGetUserSettings $hashArgs.Add('IgnoreNotSet', $true) } - return Test-WinGetUserSettings @hashArgs + return Test-WinGetUserSetting @hashArgs } # Sets the desired properties. [void] Set() { - Assert-WinGetCommand "Set-WinGetUserSettings" + Assert-WinGetCommand "Set-WinGetUserSetting" $hashArgs = @{ UserSettings = $this.Settings @@ -115,7 +115,7 @@ class WinGetUserSettings $hashArgs.Add('Merge', $true) } - Set-WinGetUserSettings @hashArgs + Set-WinGetUserSetting @hashArgs } } @@ -134,8 +134,8 @@ class WinGetAdminSettings # Gets the administrator settings. [WinGetAdminSettings] Get() { - Assert-WinGetCommand "Get-WinGetSettings" - $settingsJson = Get-WinGetSettings + Assert-WinGetCommand "Get-WinGetSetting" + $settingsJson = Get-WinGetSetting # Get admin setting values. $result = @{ diff --git a/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 b/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 index b48f9b31c6..cc08e83906 100644 --- a/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 +++ b/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 @@ -441,13 +441,13 @@ Describe 'Export-WinGetPackage' { } } -Describe 'Get-WinGetUserSettings' { +Describe 'Get-WinGetUserSetting' { - It 'Get settings' { + It 'Get setting' { $ogSettings = @{ visual= @{ progressBar="rainbow"} ; experimentalFeatures= @{experimentalArg=$false ; experimentalCmd=$true}} SetWinGetSettingsHelper $ogSettings - $userSettings = Get-WinGetUserSettings + $userSettings = Get-WinGetUserSetting $userSettings | Should -Not -BeNullOrEmpty -ErrorAction Stop $userSettings.Count | Should -Be 2 $userSettings.visual.progressBar | Should -Be 'rainbow' @@ -457,31 +457,31 @@ Describe 'Get-WinGetUserSettings' { It 'Get settings. Bad json file' { Set-Content -Path $settingsFilePath -Value "Hi, im not a json. Thank you, Test." - { Get-WinGetUserSettings } | Should -Throw + { Get-WinGetUserSetting } | Should -Throw } } -Describe 'Test-WinGetUserSettings' { +Describe 'Test-WinGetUserSetting' { It 'Bad json file' { Set-Content -Path $settingsFilePath -Value "Hi, im not a json. Thank you, Test." $inputSettings = @{ visual= @{ progressBar="retro"} } - Test-WinGetUserSettings -UserSettings $inputSettings | Should -Be $false + Test-WinGetUserSetting -UserSettings $inputSettings | Should -Be $false } It 'Equal' { $ogSettings = @{ visual= @{ progressBar="retro"} ; experimentalFeatures= @{experimentalArg=$false ; experimentalCmd=$true}} SetWinGetSettingsHelper $ogSettings - Test-WinGetUserSettings -UserSettings $ogSettings | Should -Be $true + Test-WinGetUserSetting -UserSettings $ogSettings | Should -Be $true } It 'Equal. Ignore schema' { Set-Content -Path $settingsFilePath -Value '{ "$schema": "https://aka.ms/winget-settings.schema.json", "visual": { "progressBar": "retro" } }' $inputSettings = @{ visual= @{ progressBar="retro"} } - Test-WinGetUserSettings -UserSettings $inputSettings | Should -Be $true + Test-WinGetUserSetting -UserSettings $inputSettings | Should -Be $true } It 'Not Equal string' { @@ -489,7 +489,7 @@ Describe 'Test-WinGetUserSettings' { SetWinGetSettingsHelper $ogSettings $inputSettings = @{ visual= @{ progressBar="retro"} ; experimentalFeatures= @{experimentalArg=$false ; experimentalCmd=$true}} - Test-WinGetUserSettings -UserSettings $inputSettings | Should -Be $false + Test-WinGetUserSetting -UserSettings $inputSettings | Should -Be $false } It 'Not Equal bool' { @@ -497,7 +497,7 @@ Describe 'Test-WinGetUserSettings' { SetWinGetSettingsHelper $ogSettings $inputSettings = @{ visual= @{ progressBar="rainbow"} ; experimentalFeatures= @{experimentalArg=$false ; experimentalCmd=$true}} - Test-WinGetUserSettings -UserSettings $inputSettings | Should -Be $false + Test-WinGetUserSetting -UserSettings $inputSettings | Should -Be $false } It 'Not Equal. More settings' { @@ -505,7 +505,7 @@ Describe 'Test-WinGetUserSettings' { SetWinGetSettingsHelper $ogSettings $inputSettings = @{ visual= @{ progressBar="rainbow"} ; experimentalFeatures= @{experimentalArg=$false }} - Test-WinGetUserSettings -UserSettings $inputSettings | Should -Be $false + Test-WinGetUserSetting -UserSettings $inputSettings | Should -Be $false } It 'Not Equal. More settings input' { @@ -513,14 +513,14 @@ Describe 'Test-WinGetUserSettings' { SetWinGetSettingsHelper $ogSettings $inputSettings = @{ visual= @{ progressBar="rainbow"} ; experimentalFeatures= @{experimentalArg=$false ; experimentalCmd=$true}} - Test-WinGetUserSettings -UserSettings $inputSettings | Should -Be $false + Test-WinGetUserSetting -UserSettings $inputSettings | Should -Be $false } It 'Equal IgnoreNotSet' { $ogSettings = @{ visual= @{ progressBar="retro"} ; experimentalFeatures= @{experimentalArg=$false ; experimentalCmd=$true}} SetWinGetSettingsHelper $ogSettings - Test-WinGetUserSettings -UserSettings $ogSettings -IgnoreNotSet | Should -Be $true + Test-WinGetUserSetting -UserSettings $ogSettings -IgnoreNotSet | Should -Be $true } It 'Equal IgnoreNotSet. More settings' { @@ -528,7 +528,7 @@ Describe 'Test-WinGetUserSettings' { SetWinGetSettingsHelper $ogSettings $inputSettings = @{ visual= @{ progressBar="rainbow"} ; experimentalFeatures= @{experimentalArg=$false }} - Test-WinGetUserSettings -UserSettings $inputSettings -IgnoreNotSet | Should -Be $true + Test-WinGetUserSetting -UserSettings $inputSettings -IgnoreNotSet | Should -Be $true } It 'Not Equal IgnoreNotSet. More settings input' { @@ -536,7 +536,7 @@ Describe 'Test-WinGetUserSettings' { SetWinGetSettingsHelper $ogSettings $inputSettings = @{ visual= @{ progressBar="rainbow"} ; experimentalFeatures= @{experimentalArg=$false ; experimentalCmd=$true}} - Test-WinGetUserSettings -UserSettings $inputSettings -IgnoreNotSet | Should -Be $false + Test-WinGetUserSetting -UserSettings $inputSettings -IgnoreNotSet | Should -Be $false } It 'Not Equal bool IgnoreNotSet' { @@ -544,7 +544,7 @@ Describe 'Test-WinGetUserSettings' { SetWinGetSettingsHelper $ogSettings $inputSettings = @{ visual= @{ progressBar="rainbow"} ; experimentalFeatures= @{experimentalArg=$false ; experimentalCmd=$true}} - Test-WinGetUserSettings -UserSettings $inputSettings -IgnoreNotSet | Should -Be $false + Test-WinGetUserSetting -UserSettings $inputSettings -IgnoreNotSet | Should -Be $false } It 'Not Equal array IgnoreNotSet' { @@ -552,7 +552,7 @@ Describe 'Test-WinGetUserSettings' { SetWinGetSettingsHelper $ogSettings $inputSettings = @{ installBehavior= @{ preferences= @{ architectures = @("x86", "arm64")} }} - Test-WinGetUserSettings -UserSettings $inputSettings -IgnoreNotSet | Should -Be $false + Test-WinGetUserSetting -UserSettings $inputSettings -IgnoreNotSet | Should -Be $false } It 'Not Equal wrong type IgnoreNotSet' { @@ -560,22 +560,23 @@ Describe 'Test-WinGetUserSettings' { SetWinGetSettingsHelper $ogSettings $inputSettings = @{ visual= @{ progressBar="rainbow"} ; experimentalFeatures= @{experimentalArg=4 ; experimentalCmd=$true}} - Test-WinGetUserSettings -UserSettings $inputSettings -IgnoreNotSet | Should -Be $false + Test-WinGetUserSetting -UserSettings $inputSettings -IgnoreNotSet | Should -Be $false } + AfterAll { SetWinGetSettingsHelper @{ debugging= @{ enableSelfInitiatedMinidump=$true ; keepAllLogFiles=$true } } } } -Describe 'Set-WinGetUserSettings' { +Describe 'Set-WinGetUserSetting' { It 'Overwrites' { $ogSettings = @{ source= @{ autoUpdateIntervalInMinutes=3}} SetWinGetSettingsHelper $ogSettings $inputSettings = @{ visual= @{ progressBar="rainbow"} ; experimentalFeatures= @{experimentalArg=$true ; experimentalCmd=$false}} - $result = Set-WinGetUserSettings -UserSettings $inputSettings + $result = Set-WinGetUserSetting -UserSettings $inputSettings $result | Should -Not -BeNullOrEmpty -ErrorAction Stop $result.'$schema' | Should -Not -BeNullOrEmpty @@ -592,7 +593,7 @@ Describe 'Set-WinGetUserSettings' { SetWinGetSettingsHelper $ogSettings $inputSettings = @{ visual= @{ progressBar="rainbow"} ; experimentalFeatures= @{experimentalArg=$true ; experimentalCmd=$false}} - $result = Set-WinGetUserSettings -UserSettings $inputSettings -Merge + $result = Set-WinGetUserSetting -UserSettings $inputSettings -Merge $result | Should -Not -BeNullOrEmpty -ErrorAction Stop $result.'$schema' | Should -Not -BeNullOrEmpty @@ -609,7 +610,7 @@ Describe 'Set-WinGetUserSettings' { Set-Content -Path $settingsFilePath -Value '{ "$schema": "https://aka.ms/winget-settings.schema.json", "visual": { "progressBar": "retro" } }' $inputSettings = @{ visual= @{ progressBar="retro"} } - $result = Set-WinGetUserSettings -UserSettings $inputSettings + $result = Set-WinGetUserSetting -UserSettings $inputSettings $result | Should -Not -BeNullOrEmpty -ErrorAction Stop $result.'$schema' | Should -Not -BeNullOrEmpty @@ -620,7 +621,7 @@ Describe 'Set-WinGetUserSettings' { Set-Content -Path $settingsFilePath -Value "Hi, im not a json. Thank you, Test." $inputSettings = @{ visual= @{ progressBar="retro"} } - $result = Set-WinGetUserSettings -UserSettings $inputSettings + $result = Set-WinGetUserSetting -UserSettings $inputSettings $result | Should -Not -BeNullOrEmpty -ErrorAction Stop $result.'$schema' | Should -Not -BeNullOrEmpty @@ -631,7 +632,7 @@ Describe 'Set-WinGetUserSettings' { Set-Content -Path $settingsFilePath -Value "Hi, im not a json. Thank you, Test." $inputSettings = @{ visual= @{ progressBar="retro"} } - { Set-WinGetUserSettings -UserSettings $inputSettings -Merge } | Should -Throw + { Set-WinGetUserSetting -UserSettings $inputSettings -Merge } | Should -Throw } AfterAll { @@ -642,7 +643,7 @@ Describe 'Set-WinGetUserSettings' { Describe 'Get|Enable|Disable-WinGetSetting' { It 'Get-WinGetSetting' { - $settings = Get-WinGetSettings + $settings = Get-WinGetSetting $settings | Should -Not -BeNullOrEmpty -ErrorAction Stop $settings.'$schema' | Should -Not -BeNullOrEmpty $settings.adminSettings | Should -Not -BeNullOrEmpty @@ -651,21 +652,21 @@ Describe 'Get|Enable|Disable-WinGetSetting' { # This tests require admin It 'Enable|Disable' { - $settings = Get-WinGetSettings + $settings = Get-WinGetSetting $settings | Should -Not -BeNullOrEmpty -ErrorAction Stop $settings.adminSettings | Should -Not -BeNullOrEmpty $settings.adminSettings.LocalManifestFiles | Should -Be $false Enable-WinGetSetting -Name LocalManifestFiles - $afterEnable = Get-WinGetSettings + $afterEnable = Get-WinGetSetting $afterEnable | Should -Not -BeNullOrEmpty -ErrorAction Stop $afterEnable.adminSettings | Should -Not -BeNullOrEmpty $afterEnable.adminSettings.LocalManifestFiles | Should -Be $true Disable-WingetSetting -Name LocalManifestFiles - $afterDisable = Get-WinGetSettings + $afterDisable = Get-WinGetSetting $afterDisable | Should -Not -BeNullOrEmpty -ErrorAction Stop $afterDisable.adminSettings | Should -Not -BeNullOrEmpty $afterDisable.adminSettings.LocalManifestFiles | Should -Be $false diff --git a/src/PowerShell/tests/Microsoft.WinGet.DSC.Tests.ps1 b/src/PowerShell/tests/Microsoft.WinGet.DSC.Tests.ps1 index 9c78a64dfc..e17ff6a764 100644 --- a/src/PowerShell/tests/Microsoft.WinGet.DSC.Tests.ps1 +++ b/src/PowerShell/tests/Microsoft.WinGet.DSC.Tests.ps1 @@ -54,7 +54,7 @@ Describe 'List available DSC resources'{ Describe 'WinGetAdminSettings' { BeforeAll { - $initialAdminSettings = (Get-WinGetSettings).adminSettings + $initialAdminSettings = (Get-WinGetSetting).adminSettings $adminSettingsHash = @{ BypassCertificatePinningForMicrosoftStore = !$initialAdminSettings.BypassCertificatePinningForMicrosoftStore; InstallerHashOverride = !$initialAdminSettings.InstallerHashOverride; @@ -100,7 +100,7 @@ Describe 'WinGetAdminSettings' { Describe 'WinGetUserSettings' { BeforeAll { # Delete existing user settings file. - $settingsFilePath = (Get-WinGetSettings).userSettingsFile + $settingsFilePath = (Get-WinGetSetting).userSettingsFile $backupSettingsFilePath = $settingsFilePath + ".backup" if (Test-Path -Path $settingsFilePath) From 9116d5d18bc58c9dc2dc5ae48792c6576f2b0ce0 Mon Sep 17 00:00:00 2001 From: JohnMcPMS Date: Tue, 10 Sep 2024 10:24:23 -0700 Subject: [PATCH 2/2] Microsoft.WinGet.DSC improvements (and breaking change) (#4795) The goal of this PR is to get these resources to a state where we feel ready to release the module without the prerelease tag. The `WinGetUserSettings`, `WinGetAdminSettings`, and `WinGetPackageManager` resources were deemed acceptable in their current state. The `WinGetSources` resource was decided to be overly complicated and likely not heavily used yet (and containing some bugs), so it was removed in favor of a new `WinGetSource` resource for managing individual sources. The `WinGetPackage` resource was updated to be better in line with best practices but should still be compatible unless one was using `Get`. ## Change The `WinGetSources` resource was replaced with a `WinGetSource` resource that manages a single source. The `WinGetSources` resource can continue to be used by specifying one of the module versions that contains it, but once released, new configurations should prefer the `WinGetSource` resource from the latest module. While there is no way to include or discover help via the module, I documented the resources similarly to the cmdlet documentation format. These can be used as the basis for official documentation, or we can put a link to them in the PowerShell Gallery listing (maybe updating the `Project Site` to point to a new landing page for the DSC resources). The updates to `WinGetPackage` aim to have it follow best practices and make general improvements: - Mark `Source` as a `Key` - Validate with existing attributes where possible - Not updating `$this` in calls to `Get`/`Set`/`Test` - Using the configurable properties to report values with `Get` - `IsInstalled` is reported via `Ensure` (true => `Present`, false => `Absent`) - `InstalledVersion` is reported via `Version` - `IsUpdateAvailable` is reported via `UseLatest` (they will have the opposite boolean value from each other) Any existing (non-`Get`) uses of the resource should continue to work as they did before. Smaller updates worth mentioning: - Updated the `winget configure validate` functionality to handle the new `WinGetSource` resource instead of `WinGetSources`. - Removed the error when giving both a `Version` and `UseLatest` to the `WinGetPackage` resource. `UseLatest` will override any `Version` provided if it is true. - Fixed a bug with COM `PackageCatalogInfo::TrustLevel` property reporting `None` improperly if the internal trust level contained both `Trusted` and another flag. - Renamed all of the enums in the module as there is no namespacing for enums/classes in PowerShell. --- ...igurationWingetDscModuleUnitValidation.cpp | 176 +++----- .../WinGetDscResourceValidate_Good.yml | 8 +- ...GetDscResourceValidate_PackageNotFound.yml | 8 +- ...esourceValidate_PackageVersionNotFound.yml | 8 +- ...etDscResourceValidate_SourceOpenFailed.yml | 8 +- ...onSpecifiedWithOnlyOneVersionAvailable.yml | 8 +- ...Validate_VersionSpecifiedWithUseLatest.yml | 8 +- .../PackageCatalogInfo.cpp | 14 +- .../WinGetAdminSettings.md | 24 + .../Microsoft.WinGet.DSC/WinGetPackage.md | 29 ++ .../WinGetPackageManager.md | 26 ++ .../Help/Microsoft.WinGet.DSC/WinGetSource.md | 28 ++ .../WinGetUserSettings.md | 25 ++ .../Microsoft.WinGet.DSC.psd1 | 2 +- .../Microsoft.WinGet.DSC.psm1 | 418 +++++++++--------- .../Private/HelperFunctions.ps1 | 22 - .../samples/WinGetPackageResourceSample.ps1 | 4 +- .../scripts/samples/WinGetSourceSample.ps1 | 79 ++++ .../scripts/samples/WinGetSourcesSample.ps1 | 112 ----- .../tests/Microsoft.WinGet.DSC.Tests.ps1 | 75 ++-- 20 files changed, 554 insertions(+), 528 deletions(-) create mode 100644 src/PowerShell/Help/Microsoft.WinGet.DSC/WinGetAdminSettings.md create mode 100644 src/PowerShell/Help/Microsoft.WinGet.DSC/WinGetPackage.md create mode 100644 src/PowerShell/Help/Microsoft.WinGet.DSC/WinGetPackageManager.md create mode 100644 src/PowerShell/Help/Microsoft.WinGet.DSC/WinGetSource.md create mode 100644 src/PowerShell/Help/Microsoft.WinGet.DSC/WinGetUserSettings.md delete mode 100644 src/PowerShell/Microsoft.WinGet.DSC/Private/HelperFunctions.ps1 create mode 100644 src/PowerShell/scripts/samples/WinGetSourceSample.ps1 delete mode 100644 src/PowerShell/scripts/samples/WinGetSourcesSample.ps1 diff --git a/src/AppInstallerCLICore/ConfigurationWingetDscModuleUnitValidation.cpp b/src/AppInstallerCLICore/ConfigurationWingetDscModuleUnitValidation.cpp index 3a632dde4e..a8f0cfb5a0 100644 --- a/src/AppInstallerCLICore/ConfigurationWingetDscModuleUnitValidation.cpp +++ b/src/AppInstallerCLICore/ConfigurationWingetDscModuleUnitValidation.cpp @@ -14,7 +14,7 @@ namespace AppInstaller::CLI::Configuration { namespace { - constexpr static std::string_view UnitType_WinGetSources = "WinGetSources"sv; + constexpr static std::string_view UnitType_WinGetSource = "WinGetSource"sv; constexpr static std::string_view UnitType_WinGetPackage = "WinGetPackage"sv; constexpr static std::string_view WellKnownSourceName_WinGet = "winget"sv; @@ -22,10 +22,11 @@ namespace AppInstaller::CLI::Configuration constexpr static std::string_view ValueSetKey_TreatAsArray = "treatAsArray"sv; - constexpr static std::string_view WinGetSourcesValueSetKey_Sources = "sources"sv; - constexpr static std::string_view WinGetSourcesValueSetKey_SourceName = "name"sv; - constexpr static std::string_view WinGetSourcesValueSetKey_SourceType = "type"sv; - constexpr static std::string_view WinGetSourcesValueSetKey_SourceArg = "arg"sv; + constexpr static std::string_view WinGetSourceValueSetKey_Name = "name"sv; + constexpr static std::string_view WinGetSourceValueSetKey_Type = "type"sv; + constexpr static std::string_view WinGetSourceValueSetKey_Arg = "argument"sv; + constexpr static std::string_view WinGetSourceValueSetKey_Ensure = "ensure"sv; + constexpr static std::string_view WinGetSourceValueSetKey_Ensure_Present = "present"sv; constexpr static std::string_view WinGetPackageValueSetKey_Id = "id"sv; constexpr static std::string_view WinGetPackageValueSetKey_Version = "version"sv; @@ -37,6 +38,7 @@ namespace AppInstaller::CLI::Configuration std::string Name; std::string Type; std::string Arg; + bool Present = true; bool Empty() { @@ -66,64 +68,30 @@ namespace AppInstaller::CLI::Configuration return defaultIfFailed; } - std::vector ParseWinGetSourcesFromSettings(const ValueSet& settings) + WinGetSource ParseWinGetSourceFromSettings(const ValueSet& settings) { + WinGetSource result; + // Iterate through the value set as Powershell variables are case-insensitive. - std::vector result; for (auto const& settingsPair : settings) { auto settingsKey = Utility::ConvertToUTF8(settingsPair.Key()); - if (Utility::CaseInsensitiveEquals(WinGetSourcesValueSetKey_Sources, settingsKey)) - { - auto sources = settingsPair.Value().try_as(); - if (!sources) - { - return {}; - } - bool isArray = false; - for (auto const& sourcesPair : sources) - { - if (Utility::CaseInsensitiveEquals(ValueSetKey_TreatAsArray, Utility::ConvertToUTF8(sourcesPair.Key()))) - { - isArray = true; - } - else - { - auto source = sourcesPair.Value().try_as(); - if (source) - { - WinGetSource wingetSource; - for (auto const& sourcePair : source) - { - auto sourceKey = Utility::ConvertToUTF8(sourcePair.Key()); - if (Utility::CaseInsensitiveEquals(WinGetSourcesValueSetKey_SourceName, sourceKey)) - { - wingetSource.Name = GetPropertyValueAsString(sourcePair.Value()); - } - else if (Utility::CaseInsensitiveEquals(WinGetSourcesValueSetKey_SourceType, sourceKey)) - { - wingetSource.Type = GetPropertyValueAsString(sourcePair.Value()); - } - else if (Utility::CaseInsensitiveEquals(WinGetSourcesValueSetKey_SourceArg, sourceKey)) - { - wingetSource.Arg = GetPropertyValueAsString(sourcePair.Value()); - } - } - - if (!wingetSource.Empty()) - { - result.emplace_back(std::move(wingetSource)); - } - } - } - } - - if (!isArray) - { - return {}; - } - break; + if (Utility::CaseInsensitiveEquals(WinGetSourceValueSetKey_Name, settingsKey)) + { + result.Name = GetPropertyValueAsString(settingsPair.Value()); + } + else if (Utility::CaseInsensitiveEquals(WinGetSourceValueSetKey_Type, settingsKey)) + { + result.Type = GetPropertyValueAsString(settingsPair.Value()); + } + else if (Utility::CaseInsensitiveEquals(WinGetSourceValueSetKey_Arg, settingsKey)) + { + result.Arg = GetPropertyValueAsString(settingsPair.Value()); + } + else if (Utility::CaseInsensitiveEquals(WinGetSourceValueSetKey_Ensure, settingsKey)) + { + result.Present = Utility::CaseInsensitiveEquals(WinGetSourceValueSetKey_Ensure_Present, GetPropertyValueAsString(settingsPair.Value())); } } @@ -206,56 +174,48 @@ namespace AppInstaller::CLI::Configuration auto unitType = Utility::ConvertToUTF8(details.UnitType()); auto unitIntent = unit.Intent(); - if (Utility::CaseInsensitiveEquals(UnitType_WinGetSources, unitType)) + if (Utility::CaseInsensitiveEquals(UnitType_WinGetSource, unitType)) { - auto sources = ParseWinGetSourcesFromSettings(unit.Settings()); - if (sources.size() == 0) - { - AICLI_LOG(Config, Warning, << "Failed to parse WinGetSources or empty content."); - context.Reporter.Warn() << Resource::String::WinGetResourceUnitEmptyContent(Utility::LocIndView{ UnitType_WinGetSources }) << std::endl; - foundIssues = true; - } - for (auto const& source : sources) - { - // Validate basic semantics. - if (source.Name.empty()) - { - AICLI_LOG(Config, Error, << "WinGetSource unit missing required arg: Name"); - context.Reporter.Error() << Resource::String::WinGetResourceUnitMissingRequiredArg(Utility::LocIndView{ UnitType_WinGetSources }, "Name"_liv) << std::endl; - foundIssues = true; - } - if (source.Arg.empty()) - { - AICLI_LOG(Config, Error, << "WinGetSource unit missing required arg: Arg"); - context.Reporter.Error() << Resource::String::WinGetResourceUnitMissingRequiredArg(Utility::LocIndView{ UnitType_WinGetSources }, "Arg"_liv) << std::endl; - foundIssues = true; - } + auto source = ParseWinGetSourceFromSettings(unit.Settings()); - // Validate well known source or process 3rd party source. - if (IsWellKnownSourceName(source.Name)) - { - if (!ValidateWellKnownSource(source)) - { - AICLI_LOG(Config, Warning, << "WinGetSource conflicts with a well known source. Source: " << source.Name); - context.Reporter.Warn() << Resource::String::WinGetResourceUnitKnownSourceConfliction(Utility::LocIndView{ source.Name }) << std::endl; - foundIssues = true; - } - } - else - { - if (unitIntent == ConfigurationUnitIntent::Assert) - { - AICLI_LOG(Config, Warning, << "Asserting on 3rd party source: " << source.Name); - context.Reporter.Warn() << Resource::String::WinGetResourceUnitThirdPartySourceAssertion(Utility::LocIndView{ source.Name }) << std::endl; - foundIssues = true; - } - else if (unitIntent == ConfigurationUnitIntent::Apply) - { - // Add to dependency source map so it can be validated with later WinGetPackage source - m_dependenciesSourceAndUnitIdMap.emplace(Utility::FoldCase(std::string_view{ source.Name }), Utility::FoldCase(Utility::NormalizedString{ unit.Identifier() })); - } - } - } + // Validate basic semantics. + if (source.Name.empty()) + { + AICLI_LOG(Config, Error, << "WinGetSource unit missing required arg: Name"); + context.Reporter.Error() << Resource::String::WinGetResourceUnitMissingRequiredArg(Utility::LocIndView{ UnitType_WinGetSource }, "Name"_liv) << std::endl; + foundIssues = true; + } + if (source.Arg.empty() && source.Present) + { + AICLI_LOG(Config, Error, << "WinGetSource unit missing required arg: Argument"); + context.Reporter.Error() << Resource::String::WinGetResourceUnitMissingRequiredArg(Utility::LocIndView{ UnitType_WinGetSource }, "Argument"_liv) << std::endl; + foundIssues = true; + } + + // Validate well known source or process 3rd party source. + if (IsWellKnownSourceName(source.Name)) + { + if (!ValidateWellKnownSource(source)) + { + AICLI_LOG(Config, Warning, << "WinGetSource conflicts with a well known source. Source: " << source.Name); + context.Reporter.Warn() << Resource::String::WinGetResourceUnitKnownSourceConfliction(Utility::LocIndView{ source.Name }) << std::endl; + foundIssues = true; + } + } + else + { + if (unitIntent == ConfigurationUnitIntent::Assert) + { + AICLI_LOG(Config, Warning, << "Asserting on 3rd party source: " << source.Name); + context.Reporter.Warn() << Resource::String::WinGetResourceUnitThirdPartySourceAssertion(Utility::LocIndView{ source.Name }) << std::endl; + foundIssues = true; + } + else if (unitIntent == ConfigurationUnitIntent::Apply) + { + // Add to dependency source map so it can be validated with later WinGetPackage source + m_dependenciesSourceAndUnitIdMap.emplace(Utility::FoldCase(std::string_view{ source.Name }), Utility::FoldCase(Utility::NormalizedString{ unit.Identifier() })); + } + } } else if (Utility::CaseInsensitiveEquals(UnitType_WinGetPackage, unitType)) { @@ -281,8 +241,8 @@ namespace AppInstaller::CLI::Configuration } if (package.UseLatest && !package.Version.empty()) { - AICLI_LOG(Config, Error, << "WinGetPackage unit both UseLatest and Version declared. Package: " << package.Id); - context.Reporter.Error() << Resource::String::WinGetResourceUnitBothPackageVersionAndUseLatest(Utility::LocIndView{ package.Id }) << std::endl; + AICLI_LOG(Config, Warning, << "WinGetPackage unit both UseLatest and Version declared. Package: " << package.Id); + context.Reporter.Warn() << Resource::String::WinGetResourceUnitBothPackageVersionAndUseLatest(Utility::LocIndView{ package.Id }) << std::endl; foundIssues = true; } // Validate dependency source is configured. @@ -395,4 +355,4 @@ namespace AppInstaller::CLI::Configuration return !foundIssues; } -} \ No newline at end of file +} diff --git a/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_Good.yml b/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_Good.yml index 3cfea23b14..1a1cf08946 100644 --- a/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_Good.yml +++ b/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_Good.yml @@ -1,15 +1,14 @@ properties: configurationVersion: 0.2.0 resources: - - resource: Microsoft.WinGet.DSC/WinGetSources + - resource: Microsoft.WinGet.DSC/WinGetSource id: configureSource directives: description: Add test source allowPrerelease: true settings: - Sources: - - Name: TestSource - Arg: "https://localhost:5001/TestKit" + Name: TestSource + Argument: "https://localhost:5001/TestKit" - resource: Microsoft.WinGet.DSC/WinGetPackage id: testPackage dependsOn: @@ -21,4 +20,3 @@ properties: id: AppInstallerTest.TestExeInstaller source: TestSource version: "1.0.1.0" - \ No newline at end of file diff --git a/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_PackageNotFound.yml b/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_PackageNotFound.yml index 6b7633ba50..a9bbdd42ad 100644 --- a/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_PackageNotFound.yml +++ b/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_PackageNotFound.yml @@ -1,15 +1,14 @@ properties: configurationVersion: 0.2.0 resources: - - resource: Microsoft.WinGet.DSC/WinGetSources + - resource: Microsoft.WinGet.DSC/WinGetSource id: configureSource directives: description: Add test source allowPrerelease: true settings: - Sources: - - Name: TestSource - Arg: "https://localhost:5001/TestKit" + Name: TestSource + Argument: "https://localhost:5001/TestKit" - resource: Microsoft.WinGet.DSC/WinGetPackage id: testPackage dependsOn: @@ -21,4 +20,3 @@ properties: id: AppInstallerTest.DoesNotExist source: TestSource version: "1.0.1.0" - \ No newline at end of file diff --git a/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_PackageVersionNotFound.yml b/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_PackageVersionNotFound.yml index 1dacdfb090..c3d7920f63 100644 --- a/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_PackageVersionNotFound.yml +++ b/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_PackageVersionNotFound.yml @@ -1,15 +1,14 @@ properties: configurationVersion: 0.2.0 resources: - - resource: Microsoft.WinGet.DSC/WinGetSources + - resource: Microsoft.WinGet.DSC/WinGetSource id: configureSource directives: description: Add test source allowPrerelease: true settings: - Sources: - - Name: TestSource - Arg: "https://localhost:5001/TestKit" + Name: TestSource + Argument: "https://localhost:5001/TestKit" - resource: Microsoft.WinGet.DSC/WinGetPackage id: testPackage dependsOn: @@ -21,4 +20,3 @@ properties: id: AppInstallerTest.TestExeInstaller source: TestSource version: "101.0.101.0" - \ No newline at end of file diff --git a/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_SourceOpenFailed.yml b/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_SourceOpenFailed.yml index d94a17b548..e1d558a97d 100644 --- a/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_SourceOpenFailed.yml +++ b/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_SourceOpenFailed.yml @@ -1,15 +1,14 @@ properties: configurationVersion: 0.2.0 resources: - - resource: Microsoft.WinGet.DSC/WinGetSources + - resource: Microsoft.WinGet.DSC/WinGetSource id: configureSource directives: description: Add test source allowPrerelease: true settings: - Sources: - - Name: TestSourceV2 - Arg: "https://localhost:5001/TestKit" + Name: TestSourceV2 + Argument: "https://localhost:5001/TestKit" - resource: Microsoft.WinGet.DSC/WinGetPackage id: testPackage dependsOn: @@ -21,4 +20,3 @@ properties: id: AppInstallerTest.TestExeInstaller source: TestSourceV2 version: "1.0.1.0" - \ No newline at end of file diff --git a/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_VersionSpecifiedWithOnlyOneVersionAvailable.yml b/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_VersionSpecifiedWithOnlyOneVersionAvailable.yml index 3fc0f6dac2..5a40804ef7 100644 --- a/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_VersionSpecifiedWithOnlyOneVersionAvailable.yml +++ b/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_VersionSpecifiedWithOnlyOneVersionAvailable.yml @@ -1,15 +1,14 @@ properties: configurationVersion: 0.2.0 resources: - - resource: Microsoft.WinGet.DSC/WinGetSources + - resource: Microsoft.WinGet.DSC/WinGetSource id: configureSource directives: description: Add test source allowPrerelease: true settings: - Sources: - - Name: TestSource - Arg: "https://localhost:5001/TestKit" + Name: TestSource + Argument: "https://localhost:5001/TestKit" - resource: Microsoft.WinGet.DSC/WinGetPackage id: testPackage dependsOn: @@ -21,4 +20,3 @@ properties: id: AppInstallerTest.TestValidManifest source: TestSource version: "1.0.0.0" - \ No newline at end of file diff --git a/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_VersionSpecifiedWithUseLatest.yml b/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_VersionSpecifiedWithUseLatest.yml index 3b1bd82dcc..043df1e768 100644 --- a/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_VersionSpecifiedWithUseLatest.yml +++ b/src/AppInstallerCLIE2ETests/TestData/Configuration/WinGetDscResourceValidate_VersionSpecifiedWithUseLatest.yml @@ -1,15 +1,14 @@ properties: configurationVersion: 0.2.0 resources: - - resource: Microsoft.WinGet.DSC/WinGetSources + - resource: Microsoft.WinGet.DSC/WinGetSource id: configureSource directives: description: Add test source allowPrerelease: true settings: - Sources: - - Name: TestSource - Arg: "https://localhost:5001/TestKit" + Name: TestSource + Argument: "https://localhost:5001/TestKit" - resource: Microsoft.WinGet.DSC/WinGetPackage id: testPackage dependsOn: @@ -22,4 +21,3 @@ properties: source: TestSource version: "1.0.1.0" useLatest: true - \ No newline at end of file diff --git a/src/Microsoft.Management.Deployment/PackageCatalogInfo.cpp b/src/Microsoft.Management.Deployment/PackageCatalogInfo.cpp index bd35b7c047..64d9df05a6 100644 --- a/src/Microsoft.Management.Deployment/PackageCatalogInfo.cpp +++ b/src/Microsoft.Management.Deployment/PackageCatalogInfo.cpp @@ -49,15 +49,13 @@ namespace winrt::Microsoft::Management::Deployment::implementation } } winrt::Microsoft::Management::Deployment::PackageCatalogTrustLevel PackageCatalogInfo::TrustLevel() - { - switch (m_sourceDetails.TrustLevel) + { + if (WI_IsFlagSet(m_sourceDetails.TrustLevel, ::AppInstaller::Repository::SourceTrustLevel::Trusted)) { - case ::AppInstaller::Repository::SourceTrustLevel::Trusted: - return PackageCatalogTrustLevel::Trusted; - case ::AppInstaller::Repository::SourceTrustLevel::None: - default: - return PackageCatalogTrustLevel::None; - } + return PackageCatalogTrustLevel::Trusted; + } + + return PackageCatalogTrustLevel::None; } bool PackageCatalogInfo::Explicit() { diff --git a/src/PowerShell/Help/Microsoft.WinGet.DSC/WinGetAdminSettings.md b/src/PowerShell/Help/Microsoft.WinGet.DSC/WinGetAdminSettings.md new file mode 100644 index 0000000000..908d61a29e --- /dev/null +++ b/src/PowerShell/Help/Microsoft.WinGet.DSC/WinGetAdminSettings.md @@ -0,0 +1,24 @@ +--- +external help file: Microsoft.WinGet.DSC.psm1-Help.xml +Module Name: Microsoft.WinGet.DSC +ms.date: 08/28/2024 +online version: +schema: 2.0.0 +title: WinGetAdminSettings +--- + +# WinGetAdminSettings + +## SYNOPSIS +Configures WinGet administrator settings. + +## DESCRIPTION + +Allows the administrator settings to be configured or retrieved. Setting administrator settings requires administrator privileges. + +## PARAMETERS + +**Parameter**|**Attribute**|**DataType**|**Description**|**Allowed Values** +:-----|:-----|:-----|:-----|:----- +`SID`|Key|String|The SID of the user to target, or an empty string to target the current user. **Only the empty string is currently supported.**|See [security identifiers](https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/manage/understand-security-identifiers) +`Settings`|Mandatory|Hashtable|The administrator settings as a hashtable.|Inspect the `adminSettings` property of the output from `Get-WinGetSettings` diff --git a/src/PowerShell/Help/Microsoft.WinGet.DSC/WinGetPackage.md b/src/PowerShell/Help/Microsoft.WinGet.DSC/WinGetPackage.md new file mode 100644 index 0000000000..fab88c87ae --- /dev/null +++ b/src/PowerShell/Help/Microsoft.WinGet.DSC/WinGetPackage.md @@ -0,0 +1,29 @@ +--- +external help file: Microsoft.WinGet.DSC.psm1-Help.xml +Module Name: Microsoft.WinGet.DSC +ms.date: 08/28/2024 +online version: +schema: 2.0.0 +title: WinGetPackage +--- + +# WinGetPackage + +## SYNOPSIS +Configures packages through WinGet. + +## DESCRIPTION + +Allows WinGet package state to be configured. + +## PARAMETERS + +**Parameter**|**Attribute**|**DataType**|**Description**|**Allowed Values** +:-----|:-----|:-----|:-----|:----- +`Id`|Key, Mandatory|String|The identifier of a WinGet package.|Use `Find-WinGetPackage` to search for packages +`Source`|Key|String|The name of the source that provides the package. If not provided, all configured sources will be searched for the `Id`.|Use the `WinGetSources` resource to configure a source or `Get-WinGetSource` to discover the default sources +`Version`|Optional|String|The version of the package.|See the `AvailableVersions` property of output from `Find-WinGetPackage` +`Ensure`|Optional|WinGetEnsure|Whether the package should be installed (`Present`) or not (`Absent`).|`Present` (default), `Absent` +`MatchOption`|Optional|WinGetMatchOption|The method used to compare the `Id` parameter with available packages.|`Equals`, `EqualsCaseInsensitive` (default), `StartsWithCaseInsensitive`, `ContainsCaseInsensitive` +`UseLatest`|Optional|Boolean|Whether the package should updated to the latest available version. If true, takes precedence over `Version`.|`True`, `False` (default) +`InstallMode`|Optional|WinGetInstallMode|The interactivity level requested when installing.|`Default`, `Silent` (default), `Interactive` diff --git a/src/PowerShell/Help/Microsoft.WinGet.DSC/WinGetPackageManager.md b/src/PowerShell/Help/Microsoft.WinGet.DSC/WinGetPackageManager.md new file mode 100644 index 0000000000..ded325e778 --- /dev/null +++ b/src/PowerShell/Help/Microsoft.WinGet.DSC/WinGetPackageManager.md @@ -0,0 +1,26 @@ +--- +external help file: Microsoft.WinGet.DSC.psm1-Help.xml +Module Name: Microsoft.WinGet.DSC +ms.date: 08/28/2024 +online version: +schema: 2.0.0 +title: WinGetPackageManager +--- + +# WinGetPackageManager + +## SYNOPSIS +Configures the WinGet package manager package itself. + +## DESCRIPTION + +Allows the WinGet package manager package version to be configured. If multiple of the version targeting parameters are True/non-empty, they will take precedence in the following order: `UseLatest`, `UseLatestPreRelease`, `Version`. + +## PARAMETERS + +**Parameter**|**Attribute**|**DataType**|**Description**|**Allowed Values** +:-----|:-----|:-----|:-----|:----- +`SID`|Key|String|The SID of the user to target, or an empty string to target the current user. **Only the empty string is currently supported.**|See [security identifiers](https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/manage/understand-security-identifiers) +`Version`|Optional|String|A version of the WinGet package manager package.|See [the WinGet release tags](https://github.com/microsoft/winget-cli/releases) +`UseLatest`|Optional|Boolean|The latest publicly available release should be used.|`True`, `False` (default) +`UseLatestPreRelease`|Optional|Boolean|The latest preview release should be used.|`True`, `False` (default) diff --git a/src/PowerShell/Help/Microsoft.WinGet.DSC/WinGetSource.md b/src/PowerShell/Help/Microsoft.WinGet.DSC/WinGetSource.md new file mode 100644 index 0000000000..7823851ad5 --- /dev/null +++ b/src/PowerShell/Help/Microsoft.WinGet.DSC/WinGetSource.md @@ -0,0 +1,28 @@ +--- +external help file: Microsoft.WinGet.DSC.psm1-Help.xml +Module Name: Microsoft.WinGet.DSC +ms.date: 08/28/2024 +online version: +schema: 2.0.0 +title: WinGetSource +--- + +# WinGetSource + +## SYNOPSIS +Configures a WinGet source. + +## DESCRIPTION + +Allows WinGet sources to be configured or retrieved. + +## PARAMETERS + +**Parameter**|**Attribute**|**DataType**|**Description**|**Allowed Values** +:-----|:-----|:-----|:-----|:----- +`Name`|Key, Mandatory|String|The name of the source.|Any string using valid characters for Windows file names +`Argument`|Mandatory|String|The primary data defining the source; typically the URI prefix of the source.|Source type specific value +`Type`|Optional|String|The type of the source.|`Microsoft.PreIndexed.Package`, `Microsoft.Rest` +`TrustLevel`|Optional|WinGetTrustLevel|The trust level of the source, which determines how much scrutiny is placed on it when used. If undefined and the source needs to be configured, the default value is `None`.|`Undefined` (default), `None`, `Trusted` +`Explicit`|Optional|WinGetOptionalBool|Whether the source is included (`False`) or not (`True`) in commands that do not specify a source. If undefined and the source needs to be configured, the default value is `False`.|`Undefined` (default), `False`, `True` +`Ensure`|Optional|WinGetEnsure|Whether the source should exist (`Present`) or not (`Absent`).|`Present` (default), `Absent` diff --git a/src/PowerShell/Help/Microsoft.WinGet.DSC/WinGetUserSettings.md b/src/PowerShell/Help/Microsoft.WinGet.DSC/WinGetUserSettings.md new file mode 100644 index 0000000000..4d1894e07d --- /dev/null +++ b/src/PowerShell/Help/Microsoft.WinGet.DSC/WinGetUserSettings.md @@ -0,0 +1,25 @@ +--- +external help file: Microsoft.WinGet.DSC.psm1-Help.xml +Module Name: Microsoft.WinGet.DSC +ms.date: 08/28/2024 +online version: +schema: 2.0.0 +title: WinGetUserSettings +--- + +# WinGetUserSettings + +## SYNOPSIS +Configures WinGet user settings. + +## DESCRIPTION + +Allows part or all of the user settings to be configured or retrieved. + +## PARAMETERS + +**Parameter**|**Attribute**|**DataType**|**Description**|**Allowed Values** +:-----|:-----|:-----|:-----|:----- +`SID`|Key|String|The SID of the user to target, or an empty string to target the current user. **Only the empty string is currently supported.**|See [security identifiers](https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/manage/understand-security-identifiers) +`Settings`|Mandatory|Hashtable|The user settings as a hashtable.|See [the schema](https://github.com/microsoft/winget-cli/blob/master/schemas/JSON/settings/settings.schema.0.2.json) +`Action`|Optional|WinGetAction|Determines whether to overwrite (`Full`) or merge (`Partial`) the value provided in `Settings` with the current user settings.|`Full` (default), `Partial` diff --git a/src/PowerShell/Microsoft.WinGet.DSC/Microsoft.WinGet.DSC.psd1 b/src/PowerShell/Microsoft.WinGet.DSC/Microsoft.WinGet.DSC.psd1 index bc47d93385..1db7f15660 100644 --- a/src/PowerShell/Microsoft.WinGet.DSC/Microsoft.WinGet.DSC.psd1 +++ b/src/PowerShell/Microsoft.WinGet.DSC/Microsoft.WinGet.DSC.psd1 @@ -82,7 +82,7 @@ DscResourcesToExport = @( 'WinGetUserSettings' 'WinGetAdminSettings' - 'WinGetSources' + 'WinGetSource' 'WinGetPackageManager' 'WinGetPackage' ) diff --git a/src/PowerShell/Microsoft.WinGet.DSC/Microsoft.WinGet.DSC.psm1 b/src/PowerShell/Microsoft.WinGet.DSC/Microsoft.WinGet.DSC.psm1 index 749cc9d608..9873bfa4b8 100644 --- a/src/PowerShell/Microsoft.WinGet.DSC/Microsoft.WinGet.DSC.psm1 +++ b/src/PowerShell/Microsoft.WinGet.DSC/Microsoft.WinGet.DSC.psm1 @@ -3,21 +3,17 @@ using namespace System.Collections.Generic -try +# Check that we are running as an administrator +function Assert-IsAdministrator { - # Load all non-test .ps1 files in the script's directory. - Get-ChildItem -Path $PSScriptRoot\* -Filter *.ps1 -Exclude *.Tests.ps1 -Recurse | ForEach-Object { Import-Module $_.FullName } -} catch -{ - $e = $_.Exception - while ($e.InnerException) - { - $e = $e.InnerException - } + $windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent() + $windowsPrincipal = New-Object -TypeName 'System.Security.Principal.WindowsPrincipal' -ArgumentList @( $windowsIdentity ) - if (-not [string]::IsNullOrWhiteSpace($e.Message)) + $adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator + + if (-not $windowsPrincipal.IsInRole($adminRole)) { - Write-Host $e.Message -ForegroundColor Red -BackgroundColor Black + New-InvalidOperationException -Message "This resource must run as an Administrator." } } @@ -28,13 +24,13 @@ enum WinGetAction Full } -enum Ensure +enum WinGetEnsure { Absent Present } -enum MatchOption +enum WinGetMatchOption { Equals EqualsCaseInsensitive @@ -42,13 +38,20 @@ enum MatchOption ContainsCaseInsensitive } -enum InstallMode +enum WinGetInstallMode { Default Silent Interactive } +enum WinGetTrustLevel +{ + Undefined + None + Trusted +} + #endregion enums #region DscResources @@ -74,8 +77,6 @@ class WinGetUserSettings # Gets the current UserSettings by looking at the settings.json file for the current user. [WinGetUserSettings] Get() { - Assert-WinGetCommand "Get-WinGetUserSetting" - $userSettings = Get-WinGetUserSetting $result = @{ SID = '' @@ -87,8 +88,6 @@ class WinGetUserSettings # Tests if desired properties match. [bool] Test() { - Assert-WinGetCommand "Test-WinGetUserSetting" - $hashArgs = @{ UserSettings = $this.Settings } @@ -104,8 +103,6 @@ class WinGetUserSettings # Sets the desired properties. [void] Set() { - Assert-WinGetCommand "Set-WinGetUserSetting" - $hashArgs = @{ UserSettings = $this.Settings } @@ -134,7 +131,6 @@ class WinGetAdminSettings # Gets the administrator settings. [WinGetAdminSettings] Get() { - Assert-WinGetCommand "Get-WinGetSetting" $settingsJson = Get-WinGetSetting # Get admin setting values. @@ -169,8 +165,6 @@ class WinGetAdminSettings [void] Set() { Assert-IsAdministrator - Assert-WinGetCommand "Enable-WinGetSetting" - Assert-WinGetCommand "Disable-WinGetSetting" # It might be better to implement an internal Test with one value, or # create a new instances with only one setting than calling Enable/Disable @@ -193,130 +187,168 @@ class WinGetAdminSettings } [DSCResource()] -class WinGetSources +class WinGetSource { - # We need a key. Do not set. - [DscProperty(Key)] - [string]$SID - - # An array of Hashtable with the key value properties that follows the source's group policy schema. + [DscProperty(Key, Mandatory)] + [ValidateNotNullOrWhiteSpace()] + [string]$Name + [DscProperty(Mandatory)] - [Hashtable[]]$Sources - + [string]$Argument + [DscProperty()] - [Ensure]$Ensure = [Ensure]::Present - + [string]$Type + [DscProperty()] - [bool]$Reset = $false + [WinGetTrustLevel]$TrustLevel = [WinGetTrustLevel]::Undefined + + [DscProperty()] + [nullable[bool]]$Explicit = $null [DscProperty()] - [WinGetAction]$Action = [WinGetAction]::Full + [WinGetEnsure]$Ensure = [WinGetEnsure]::Present - # Gets the current sources on winget. - [WinGetSources] Get() + [WinGetSource] Get() { - Assert-WinGetCommand "Get-WinGetSource" - $packageCatalogReferences = Get-WinGetSource - $wingetSources = [List[Hashtable]]::new() - foreach ($packageCatalogReference in $packageCatalogReferences) - { - $source = @{ - $packageCatalogReference.Name = @{ - Identifier = $packageCatalogReference.Id - Arg = $packageCatalogReference.Argument - Type = $packageCatalogReference.Type - } - } - $wingetSources.Add($source) + $currentSource = $null + + try { + $currentSource = Get-WinGetSource -Name $this.Name + } + catch { } - $result = @{ - SID = '' - Sources = $wingetSources + $result = [WinGetSource]::new() + + if ($currentSource) + { + $result.Ensure = [WinGetEnsure]::Present + $result.Name = $currentSource.Name + $result.Argument = $currentSource.Argument + $result.Type = $currentSource.Type + $result.TrustLevel = $currentSource.TrustLevel + $result.Explicit = $currentSource.Explicit } + else + { + $result.Ensure = [WinGetEnsure]::Absent + $result.Name = $this.Name + } + return $result } - # Tests if desired properties match. [bool] Test() { - $currentSources = $this.Get().Sources - $currentState = [Ensure]::Present + return $this.TestAgainstCurrent($this.Get()) + } + + [void] Set() + { + Assert-IsAdministrator - # If this is a full match and the counts are different return false. This only applies if we want to ensure the full source is present. - if (($this.Action -eq [WinGetAction]::Full) -and ($this.Sources.Count -ne $currentSources.Count) -and ($this.Ensure -eq [Ensure]::Present)) + $currentSource = $this.Get() + + $removeSource = $false + $resetSource = $false + $addSource = $false + + if ($this.Ensure -eq [WinGetEnsure]::Present) { - return $false + if ($currentSource.Ensure -eq [WinGetEnsure]::Present) + { + if (-not $this.TestAgainstCurrent($currentSource)) + { + $resetSource = $true + $addSource = $true + } + # else in desired state + } + else + { + $addSource = $true + } + } + else + { + if ($currentSource.Ensure -eq [WinGetEnsure]::Present) + { + $removeSource = $true + } + # else in desired state (Absent) } - foreach ($sourceName in $this.Sources.Keys) + if ($removeSource) { - #Check if the source name exists, if it doesn't, then return false. - $result = $currentSources.Keys | Where-Object { $_ -eq $sourceName } - if ($null -eq $result) + Remove-WinGetSource -Name $this.Name + } + # Only remove OR reset should be true, not both + elseif ($resetSource) + { + Reset-WinGetSource -Name $this.Name + } + + if ($addSource) + { + $hashArgs = @{ + Name = $this.Name + Argument = $this.Argument + } + + if (-not [string]::IsNullOrWhiteSpace($this.Type)) { - $currentState = [Ensure]::Absent + $hashArgs.Add("Type", $this.Type) } - # Type has a default value. - $source = $this.Sources.$($sourceName) - $sourceType = "Microsoft.PreIndexed.Package" # default source type - if ($source.ContainsKey("Type") -and (-not([string]::IsNullOrWhiteSpace($source.Type)))) + if ($this.TrustLevel -ne [WinGetTrustLevel]::Undefined) { - $sourceType = $source.Type + $hashArgs.Add("TrustLevel", $this.TrustLevel) } - $existingSource = $currentSources.$($sourceName) - if ($source.Arg -ne $existingSource.Arg -or $sourceType -ne $existingSource.Type) + if ($null -ne $this.Explicit) { - $currentState = [Ensure]::Absent + $hashArgs.Add("Explicit", $this.Explicit) } - } - return $currentState -eq $this.Ensure + Add-WinGetSource @hashArgs + } } - - # Sets the desired properties. - [void] Set() + + # Test $this against a value retrieved from Get + # We don't need to check Name because it is the Key for Get + [bool] hidden TestAgainstCurrent([WinGetSource]$currentSource) { - Assert-IsAdministrator - Assert-WinGetCommand "Add-WinGetSource" - Assert-WinGetCommand "Reset-WinGetSource" - Assert-WinGetCommand "Remove-WinGetSource" + if ($this.Ensure -eq [WinGetEnsure]::Absent -and + $currentSource.Ensure -eq [WinGetEnsure]::Absent) + { + return $true + } - if (-not $this.Test()) + if ($this.Ensure -ne $currentSource.Ensure -or + $this.Argument -ne $currentSource.Argument) { - foreach ($sourceName in $this.Sources.Keys) - { - $sourceType = "Microsoft.PreIndexed.Package" - $source = $this.Sources.$($sourceName) - - if ((-not $source.ContainsKey("Arg")) -or [string]::IsNullOrWhiteSpace($source.Arg)) - { - # TODO: Localize. - throw "Invalid source input. Arg is required." - } - - if ($source.ContainsKey("Type") -and (-not([string]::IsNullOrWhiteSpace($source.Type)))) - { - $sourceType = $source.Type - } - - if ($this.Ensure -eq [Ensure]::Present) - { - Add-WinGetSource -Name $sourceName -Argument $source.Arg -Type $sourceType - - if ($this.Reset) - { - Reset-WinGetSource -Name $sourceName - } - } - else - { - Remove-WinGetSource -Name $sourceName - } - } + return $false + } + + if (-not([string]::IsNullOrWhiteSpace($this.Type)) -and + $this.Type -ne $currentSource.Type) + { + return $false + } + + if ($this.TrustLevel -ne [WinGetTrustLevel]::Undefined -and + $this.TrustLevel -ne $currentSource.TrustLevel) + { + return $false } + + if ($null -ne $this.Explicit -and + $this.Explicit -ne $currentSource.Explicit) + { + return $false + } + + return $true } } @@ -353,9 +385,6 @@ class WinGetPackageManager # Tests winget is installed. [bool] Test() { - Assert-WinGetCommand "Assert-WinGetPackageManager" - Assert-WinGetCommand "Get-WinGetVersion" - try { $hashArgs = @{} @@ -385,8 +414,6 @@ class WinGetPackageManager # Repairs Winget. [void] Set() { - Assert-WinGetCommand "Repair-WinGetPackageManager" - if (-not $this.Test()) { $result = -1 @@ -419,119 +446,73 @@ class WinGetPackageManager class WinGetPackage { [DscProperty(Key, Mandatory)] + [ValidateNotNullOrWhiteSpace()] [string]$Id - [DscProperty()] - [string]$Version + [DscProperty(Key)] + [string]$Source [DscProperty()] - [string]$Source + [string]$Version [DscProperty()] - [Ensure]$Ensure = [Ensure]::Present + [WinGetEnsure]$Ensure = [WinGetEnsure]::Present [DscProperty()] - [MatchOption]$MatchOption = [MatchOption]::EqualsCaseInsensitive + [WinGetMatchOption]$MatchOption = [WinGetMatchOption]::EqualsCaseInsensitive [DscProperty()] [bool]$UseLatest = $false [DSCProperty()] - [InstallMode]$InstallMode = [InstallMode]::Silent - - [DscProperty(NotConfigurable)] - [string]$InstalledVersion - - [DscProperty(NotConfigurable)] - [bool]$IsInstalled = $false - - [DscProperty(NotConfigurable)] - [bool]$IsUpdateAvailable = $false + [WinGetInstallMode]$InstallMode = [WinGetInstallMode]::Silent [PSObject] hidden $CatalogPackage = $null - hidden Initialize() - { - # DSC only validates keys and mandatories in a Set call. - if ([string]::IsNullOrWhiteSpace($this.Id)) - { - # TODO: Localize. - throw "WinGetPackage: Id is required" - } - - if (($this.UseLatest -eq $true) -and (-not[string]::IsNullOrWhiteSpace($this.Version))) - { - # TODO: Localize. - throw "WinGetPackage: Version and UseLatest cannot be set at the same time" - } - - # This has to use MatchOption equals. Otherwise, it might find other package where the - # id starts with. - $this.CatalogPackage = Get-WinGetPackage -Id $this.Id -MatchOption $this.MatchOption - if ($null -ne $this.CatalogPackage) - { - $this.InstalledVersion = $this.CatalogPackage.InstalledVersion - $this.IsInstalled = $true - $this.IsUpdateAvailable = $this.CatalogPackage.IsUpdateAvailable - } - } - - # Get. [WinGetPackage] Get() { - Assert-WinGetCommand "Get-WinGetPackage" - $this.Initialize() - return $this - } + $result = [WinGetPackage]::new() - # Test. - [bool] Test() - { - $this.Initialize() - $ensureInstalled = $this.Ensure -eq [Ensure]::Present - - # Not installed, doesn't have to. - if (-not($this.IsInstalled -or $ensureInstalled)) - { - return $true + $hashArgs = @{ + Id = $this.Id + MatchOption = $this.MatchOption } - # Not install, need to ensure installed. - # Installed, need to ensure not installed. - if ($this.IsInstalled -ne $ensureInstalled) + if (-not([string]::IsNullOrWhiteSpace($this.Source))) { - return $false + $hashArgs.Add("Source", $this.Source) } - # At this point we know is installed. - # If asked for latests, but there are updates available. - if ($this.UseLatest -and - $this.CatalogPackage.IsUpdateAvailable) + $result.CatalogPackage = Get-WinGetPackage @hashArgs + if ($null -ne $result.CatalogPackage) { - return $false + $result.Ensure = [WinGetEnsure]::Present + $result.Id = $result.CatalogPackage.Id + $result.Source = $result.CatalogPackage.Source + $result.Version = $result.CatalogPackage.InstalledVersion + $result.UseLatest = -not $result.CatalogPackage.IsUpdateAvailable } - - # If there is an specific version, compare with the current installed version. - if (-not ([string]::IsNullOrWhiteSpace($this.Version))) + else { - $compareResult = $this.CatalogPackage.CompareToVersion($this.Version) - if ($compareResult -ne 'Equal') - { - return $false - } + $result.Ensure = [WinGetEnsure]::Absent + $result.Id = $this.Id + $result.MatchOption = $this.MatchOption + $result.Source = $this.Source } - # For now this is all. - return $true + return $result + } + + [bool] Test() + { + return $this.TestAgainstCurrent($this.Get()) } - # Set. [void] Set() { - Assert-WinGetCommand "Install-WinGetPackage" - Assert-WinGetCommand "Uninstall-WinGetPackage" + $currentPackage = $this.Get() - if (-not $this.Test()) + if (-not $this.TestAgainstCurrent($currentPackage)) { $hashArgs = @{ Id = $this.Id @@ -539,14 +520,14 @@ class WinGetPackage Mode = $this.InstallMode } - if ($this.Ensure -eq [Ensure]::Present) + if ($this.Ensure -eq [WinGetEnsure]::Present) { if (-not([string]::IsNullOrWhiteSpace($this.Source))) { $hashArgs.Add("Source", $this.Source) } - if ($this.IsInstalled) + if ($currentPackage.Ensure -eq [WinGetEnsure]::Present) { if ($this.UseLatest) { @@ -556,7 +537,7 @@ class WinGetPackage { $hashArgs.Add("Version", $this.Version) - $compareResult = $this.CatalogPackage.CompareToVersion($this.Version) + $compareResult = $currentPackage.CatalogPackage.CompareToVersion($this.Version) switch ($compareResult) { 'Lesser' @@ -590,6 +571,43 @@ class WinGetPackage } } } + + [bool] hidden TestAgainstCurrent([WinGetPackage]$currentPackage) + { + if ($this.Ensure -eq [WinGetEnsure]::Absent -and + $currentPackage.Ensure -eq [WinGetEnsure]::Absent) + { + return $true + } + + $this.CatalogPackage = $currentPackage.CatalogPackage + + if ($this.Ensure -ne $currentPackage.Ensure) + { + return $false + } + + # At this point we know is installed. + # If asked for latest, but there are updates available. + if ($this.UseLatest) + { + if (-not $currentPackage.UseLatest) + { + return $false + } + } + # If there is an specific version, compare with the current installed version. + elseif (-not ([string]::IsNullOrWhiteSpace($this.Version))) + { + $compareResult = $currentPackage.CatalogPackage.CompareToVersion($this.Version) + if ($compareResult -ne 'Equal') + { + return $false + } + } + + return $true + } hidden Install([Hashtable]$hashArgs) { diff --git a/src/PowerShell/Microsoft.WinGet.DSC/Private/HelperFunctions.ps1 b/src/PowerShell/Microsoft.WinGet.DSC/Private/HelperFunctions.ps1 deleted file mode 100644 index 0af9fabfc3..0000000000 --- a/src/PowerShell/Microsoft.WinGet.DSC/Private/HelperFunctions.ps1 +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -# Check that we are running as an administrator -function Assert-IsAdministrator -{ - $windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent() - $windowsPrincipal = New-Object -TypeName 'System.Security.Principal.WindowsPrincipal' -ArgumentList @( $windowsIdentity ) - - $adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator - - if (-not $windowsPrincipal.IsInRole($adminRole)) - { - New-InvalidOperationException -Message "This resource must run as an Administrator." - } -} - -# Verify the command is present in the Microsoft.WinGet.Client Module -function Assert-WinGetCommand([string]$cmdletName) -{ - $null = Get-Command -Module "Microsoft.WinGet.Client" -Name $cmdletName -ErrorAction Stop -} diff --git a/src/PowerShell/scripts/samples/WinGetPackageResourceSample.ps1 b/src/PowerShell/scripts/samples/WinGetPackageResourceSample.ps1 index 046871b9d5..1af5d0d439 100644 --- a/src/PowerShell/scripts/samples/WinGetPackageResourceSample.ps1 +++ b/src/PowerShell/scripts/samples/WinGetPackageResourceSample.ps1 @@ -26,11 +26,11 @@ $resource = @{ $testResult = Invoke-DscResource @resource -Method Test if ($testResult.InDesiredState) { - Write-Host "PowerToys is installed." + Write-Host "PowerToys is not installed." } else { - Write-Host "PowerToys is not installed." + Write-Host "PowerToys is installed." } # Default value of Ensure is present. diff --git a/src/PowerShell/scripts/samples/WinGetSourceSample.ps1 b/src/PowerShell/scripts/samples/WinGetSourceSample.ps1 new file mode 100644 index 0000000000..1ea136065c --- /dev/null +++ b/src/PowerShell/scripts/samples/WinGetSourceSample.ps1 @@ -0,0 +1,79 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +<# + .SYNOPSIS + Simple sample on how to use WinGetSourceResource DSC resource. + Requires PSDesiredStateConfiguration version 2.0.6 + + IMPORTANT: This deletes the main winget source and add it again. + Run as admin for set. +#> + +#Requires -Modules Microsoft.WinGet.Client, Microsoft.WinGet.DSC + +using module Microsoft.WinGet.DSC +using namespace System.Collections.Generic + +[CmdletBinding()] +param ( + [Parameter()] + [string] + $SourceName = "winget", + + [Parameter()] + [string] + $Argument = "https://cdn.winget.microsoft.com/cache", + + [Parameter()] + [string] + $Type = "" +) + +$resource = @{ + Name = 'WinGetSourceResource' + ModuleName = 'Microsoft.WinGet.DSC' + Property = @{ + Name = $SourceName + } +} + +$getResult = Invoke-DscResource @resource -Method Get +Write-Host "Current sources" +Format-List $getResult -Force + +$resource.Property = @{ + Argument = $Argument + Type = $Type +} + +# The default value comparison for test is Partial, so if you have the winget source this should succeed. +$testResult = Invoke-DscResource @resource -Method Test +if ($testResult.InDesiredState) +{ + Write-Host "winget source is present" +} +else +{ + Write-Host "winget source is not present" + return +} + +# Removing winget. Note this will fail if not run as admin. +$resource.Property = @{ + Ensure = [Ensure]::Absent +} + +Invoke-DscResource @resource -Method Set | Out-Null +Write-Host "winget source removed" + +# Test again +$testResult = Invoke-DscResource @resource -Method Test +if (-not $testResult.InDesiredState) +{ + Write-Host "winget source is still present." +} +else +{ + Write-Host "winget was removed." +} diff --git a/src/PowerShell/scripts/samples/WinGetSourcesSample.ps1 b/src/PowerShell/scripts/samples/WinGetSourcesSample.ps1 deleted file mode 100644 index 3148671266..0000000000 --- a/src/PowerShell/scripts/samples/WinGetSourcesSample.ps1 +++ /dev/null @@ -1,112 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -<# - .SYNOPSIS - Simple sample on how to use WinGetSourcesResource DSC resource. - Requires PSDesiredStateConfiguration version 2.0.6 - - IMPORTANT: This deletes the main winget source and add it again. - Run as admin for set. -#> - -#Requires -Modules Microsoft.WinGet.Client, Microsoft.WinGet.DSC - -using module Microsoft.WinGet.DSC -using namespace System.Collections.Generic - -[CmdletBinding()] -param ( - [Parameter()] - [string] - $SourceName = "winget", - - [Parameter()] - [string] - $Argument = "https://cdn.winget.microsoft.com/cache", - - [Parameter()] - [string] - $Type = "" -) - -$resource = @{ - Name = 'WinGetSourcesResource' - ModuleName = 'Microsoft.WinGet.DSC' - Property = @{ - } -} - -$getResult = Invoke-DscResource @resource -Method Get -Write-Host "Current sources" - -foreach ($source in $getResult.Sources) -{ - Write-Host "Name '$($source.Name)' Arg '$($source.Arg)' Type '$($source.Type)'" -} - -$expectedSources = [List[Hashtable]]::new() -$expectedSources.Add(@{ - Name = "winget" - Arg = "https://cdn.winget.microsoft.com/cache" -}) - -$resource.Property = @{ - Sources = $expectedSources - Action = [WinGetAction]::Partial -} - -# The default value comparison for test is Partial, so if you have the winget source this should succeed. -$testResult = Invoke-DscResource @resource -Method Test -if ($testResult.InDesiredState) -{ - Write-Host "winget source is present" -} -else -{ - Write-Host "winget source is not present" - return -} - -# A full match will fail if there are more sources. -$resource.Property = @{ - Sources = $expectedSources - Action = [WinGetAction]::Full -} -$testResult = Invoke-DscResource @resource -Method Test -if (-not $testResult.InDesiredState) -{ - Write-Host "winget source is not the only source" -} -else -{ - Write-Host "winget source is the only source" -} - -# Breaking winget. Note this will fail if not run as admin. -$resource.Property = @{ - Sources = $expectedSources - Action = [WinGetAction]::Partial - Ensure = [Ensure]::Absent -} - -Invoke-DscResource @resource -Method Set | Out-Null -Write-Host "winget source removed" - -# Test again -$testResult = Invoke-DscResource @resource -Method Test -if (-not $testResult.InDesiredState) -{ - Write-Host "winget source is gone." - - # Add it again - $resource.Property.Command = [SourceCommand]::Add - Invoke-DscResource @resource -Method Set | Out-Null -} -else -{ - # TODO: debug. Basically when `winget source remove winget` happens if the - # commands prints the progress bar the source was not removed. I think that - # it was actually removed but readded updating the package. - Write-Host "winget was not removed." -} diff --git a/src/PowerShell/tests/Microsoft.WinGet.DSC.Tests.ps1 b/src/PowerShell/tests/Microsoft.WinGet.DSC.Tests.ps1 index e17ff6a764..0dc01f6dd8 100644 --- a/src/PowerShell/tests/Microsoft.WinGet.DSC.Tests.ps1 +++ b/src/PowerShell/tests/Microsoft.WinGet.DSC.Tests.ps1 @@ -28,23 +28,11 @@ BeforeAll { return Invoke-DscResource -Name $Name -ModuleName Microsoft.WinGet.DSC -Method $Method -Property $Property } - - function AddTestSource { - try { - Get-WinGetSource -Name 'TestSource' - } - catch { - # TODO: Add-WinGetSource does not support setting trust level yet. - # Add-WinGetSource -Name 'TestSource' -Arg 'https://localhost:5001/TestKit/' - $sourceAddCommand = "wingetdev.exe source add TestSource https://localhost:5001/TestKit/ --trust-level trusted" - Invoke-Expression -Command $sourceAddCommand - } - } } Describe 'List available DSC resources'{ It 'Shows DSC Resources'{ - $expectedDSCResources = "WinGetAdminSettings", "WinGetPackage", "WinGetPackageManager", "WinGetSources", "WinGetUserSettings" + $expectedDSCResources = "WinGetAdminSettings", "WinGetPackage", "WinGetPackageManager", "WinGetSource", "WinGetUserSettings" $availableDSCResources = (Get-DscResource -Module Microsoft.WinGet.DSC).Name $availableDSCResources.length | Should -Be 5 $availableDSCResources | Where-Object {$expectedDSCResources -notcontains $_} | Should -BeNullOrEmpty -ErrorAction Stop @@ -140,58 +128,55 @@ Describe 'WinGetUserSettings' { } } -Describe 'WinGetSources' { +Describe 'WinGetSource' { BeforeAll { $testSourceName = 'TestSource' + $testSourceArg = 'https://localhost:5001/TestKit/' + $testSourceType = 'Microsoft.PreIndexed.Package' - $testSourceValue = @{ - Type = 'Microsoft.PreIndexed.Package' - Arg = 'https://localhost:5001/TestKit/' - } - - InvokeWinGetDSC -Name WinGetSources -Method Set -Property @{ Action = 'Partial'; Ensure = 'Absent'; Sources = @{ $testSourceName = $testSourceValue }} + InvokeWinGetDSC -Name WinGetSource -Method Set -Property @{ Ensure = 'Absent'; Name = $testSourceName } } It 'Get WinGet source' { - $result = InvokeWinGetDSC -Name WinGetSources -Method Get -Property @{ Sources = @{ $testSourceName = $testSourceValue }} - $result.Sources.Keys | Should -Not -Contain $testSourceName + $result = InvokeWinGetDSC -Name WinGetSource -Method Get -Property @{ Name = $testSourceName } + $result.Ensure | Should -Be 'Absent' } It 'Test WinGet source' { - $result = InvokeWinGetDSC -Name WinGetSources -Method Test -Property @{ Ensure='Present'; Sources = @{ $testSourceName = $testSourceValue }} + $result = InvokeWinGetDSC -Name WinGetSource -Method Test -Property @{ Ensure='Present'; Name = $testSourceName; Argument = $testSourceArg; Type = $testSourceType } $result.InDesiredState | Should -Be $false } It 'Set WinGet source' { - # InvokeWinGetDSC -Name WinGetSources -Method Set -Property @{ Ensure = 'Present'; Sources = @{ $testSourceName = $testSourceValue }} - # TODO: Replace with DSC once '--trust-level' is supported - AddTestSource + InvokeWinGetDSC -Name WinGetSource -Method Set -Property @{ Name = $testSourceName; Argument = $testSourceArg; Type = $testSourceType; TrustLevel = 'Trusted'; Explicit = $true } - $result = InvokeWinGetDSC -Name WinGetSources -Method Get -Property @{ Sources = @{ $testSourceName = $testSourceValue }} - $result.Sources.Keys | Should -Contain $testSourceName + $result = InvokeWinGetDSC -Name WinGetSource -Method Test -Property @{ Name = $testSourceName; Argument = $testSourceArg; Type = $testSourceType } + $result.InDesiredState | Should -Be $true - $testSource = $result.Sources.$($testSourceName) - $testSource.Type | Should -Be 'Microsoft.PreIndexed.Package' - $testSource.Arg | Should -Be 'https://localhost:5001/TestKit/' - $testSource.Identifier | Should -Be $null + $result = InvokeWinGetDSC -Name WinGetSource -Method Get -Property @{ Name = $testSourceName } + $result.Name | Should -Be $testSourceName + $result.Type | Should -Be $testSourceType + $result.Argument | Should -Be $testSourceArg + $result.TrustLevel | Should -Be 'Trusted' + $result.Explicit | Should -Be $true } } Describe 'WinGetPackage' { BeforeAll { + $testSourceName = 'TestSource' + $testSourceArg = 'https://localhost:5001/TestKit/' + $testSourceType = 'Microsoft.PreIndexed.Package' + $testPackageId = 'AppInstallerTest.TestExeInstaller' $testPackageVersion = '1.0.0.0' - # Add test source. - # InvokeWinGetDSC -Name WinGetSources -Method Set -Property @{ Action = 'Partial'; Ensure = 'Present'; Sources = @{ TestSource = @{ Arg = 'https://localhost:5001/TestKit/'; Type = 'Microsoft.PreIndexed.Package' }}} - - # TODO: Replace with DSC once '--trust-level' is supported. - AddTestSource + InvokeWinGetDSC -Name WinGetSource -Method Set -Property @{ Name = $testSourceName; Argument = $testSourceArg; Type = $testSourceType; TrustLevel = 'Trusted' } } It 'Get WinGetPackage' { $result = InvokeWinGetDSC -Name WinGetPackage -Method Get -Property @{ Id = $testPackageId; Version = $testPackageVersion } - $result.IsInstalled | Should -Be $false + $result.Ensure | Should -Be 'Absent' } It 'Test WinGetPackage' { @@ -204,9 +189,9 @@ Describe 'WinGetPackage' { # Verify package installed. $result = InvokeWinGetDSC -Name WinGetPackage -Method Get -Property @{ Id = $testPackageId; Version = $testPackageVersion } - $result.IsInstalled | Should -Be $true - $result.IsUpdateAvailable | Should -Be $true - $result.InstalledVersion | Should -Be 1.0.0.0 + $result.Ensure | Should -Be 'Present' + $result.UseLatest | Should -Be $false + $result.Version | Should -Be $testPackageVersion } It 'Update WinGetPackage' { @@ -217,9 +202,9 @@ Describe 'WinGetPackage' { # Verify package updated. $result = InvokeWinGetDSC -Name WinGetPackage -Method Get -Property @{ Id = $testPackageId; UseLatest = $true } - $result.IsInstalled | Should -Be $true - $result.IsUpdateAvailable | Should -Be $false - $result.InstalledVersion | Should -Not -Be 1.0.0.0 + $result.Ensure | Should -Be 'Present' + $result.UseLatest | Should -Be $true + $result.Version | Should -Not -Be $testPackageVersion } It 'Uninstall WinGetPackage' { @@ -232,7 +217,7 @@ Describe 'WinGetPackage' { # Verify package uninstalled. $result = InvokeWinGetDSC -Name WinGetPackage -Method Get -Property @{ Ensure = 'Absent'; Id = $testPackageId } - $result.IsInstalled | Should -Be $false + $result.Ensure | Should -Be 'Absent' } AfterAll {