diff --git a/src/PowerShell/Help/Microsoft.WinGet.Client/Assert-WinGetPackageManager.md b/src/PowerShell/Help/Microsoft.WinGet.Client/Assert-WinGetPackageManager.md index 727ecf6358..176426fe28 100644 --- a/src/PowerShell/Help/Microsoft.WinGet.Client/Assert-WinGetPackageManager.md +++ b/src/PowerShell/Help/Microsoft.WinGet.Client/Assert-WinGetPackageManager.md @@ -23,7 +23,7 @@ Assert-WinGetPackageManager [-Version ] [] ### IntegrityLatestSet ``` -Assert-WinGetPackageManager [-Latest] [-IncludePreRelease] [] +Assert-WinGetPackageManager [-Latest] [-IncludePrerelease] [] ``` ## DESCRIPTION diff --git a/src/PowerShell/Help/Microsoft.WinGet.Client/Reset-WinGetSource.md b/src/PowerShell/Help/Microsoft.WinGet.Client/Reset-WinGetSource.md index 629cbd3bac..7d4630ac6f 100644 --- a/src/PowerShell/Help/Microsoft.WinGet.Client/Reset-WinGetSource.md +++ b/src/PowerShell/Help/Microsoft.WinGet.Client/Reset-WinGetSource.md @@ -10,18 +10,26 @@ title: Reset-WinGetSource # Reset-WinGetSource ## SYNOPSIS -Resets default WinGet sources. +Resets WinGet sources. ## SYNTAX +### DefaultSet (Default) + ``` Reset-WinGetSource -Name [] ``` +### OptionalSet + +``` +Reset-WinGetSource -All [] +``` + ## DESCRIPTION -Resets the current WinGet sources to the default source configurations. This command must be -executed with administrator permissions. +Resets a named WinGet source by removing the source configuration. You can reset all configured sources and add the default source configurations using the **All** switch parameter. +This command must be executed with administrator permissions. ## EXAMPLES @@ -33,15 +41,39 @@ Reset-WinGetSource -Name msstore This example resets the configured source named 'msstore' by removing it. +### Example 2: Reset all sources + +```powershell +Reset-WinGetSource -All +``` + +This example resets all configured sources and adds the default sources. + ## PARAMETERS +### -All + +Reset all sources and add the default sources. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (OptionalSet) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + ### -Name The name of the source. ```yaml Type: System.String -Parameter Sets: (All) +Parameter Sets: (DefaultSet) Aliases: Required: True diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/AssertWinGetPackageManagerCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/AssertWinGetPackageManagerCmdlet.cs index 9111fc4ed1..9e574e1824 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/AssertWinGetPackageManagerCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/AssertWinGetPackageManagerCmdlet.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. Licensed under the MIT License. // @@ -29,7 +29,7 @@ protected override void ProcessRecord() var command = new WinGetPackageManagerCommand(this); if (this.ParameterSetName == Constants.IntegrityLatestSet) { - command.AssertUsingLatest(this.IncludePreRelease.ToBool()); + command.AssertUsingLatest(this.IncludePrerelease.ToBool()); } else { diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/Common/WinGetPackageManagerCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/Common/WinGetPackageManagerCmdlet.cs index b21c6986e7..3d2f4d16d7 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/Common/WinGetPackageManagerCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/Common/WinGetPackageManagerCmdlet.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. Licensed under the MIT License. // @@ -36,6 +36,6 @@ public abstract class WinGetPackageManagerCmdlet : PSCmdlet [Parameter( ParameterSetName = Constants.IntegrityLatestSet, ValueFromPipelineByPropertyName = true)] - public SwitchParameter IncludePreRelease { get; set; } + public SwitchParameter IncludePrerelease { get; set; } } } diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/RemoveSourceCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/RemoveSourceCmdlet.cs index fbcb392a75..863620a7cb 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/RemoveSourceCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/RemoveSourceCmdlet.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. Licensed under the MIT License. // @@ -20,6 +20,7 @@ public sealed class RemoveSourceCmdlet : PSCmdlet /// Gets or sets the name of the source to remove. /// [Parameter( + Position = 0, Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/RepairWinGetPackageManagerCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/RepairWinGetPackageManagerCmdlet.cs index f35700eb27..71b8a0f7a9 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/RepairWinGetPackageManagerCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/RepairWinGetPackageManagerCmdlet.cs @@ -44,7 +44,7 @@ protected override void ProcessRecord() this.command = new WinGetPackageManagerCommand(this); if (this.ParameterSetName == Constants.IntegrityLatestSet) { - this.command.RepairUsingLatest(this.IncludePreRelease.ToBool(), this.AllUsers.ToBool(), this.Force.ToBool()); + this.command.RepairUsingLatest(this.IncludePrerelease.ToBool(), this.AllUsers.ToBool(), this.Force.ToBool()); } else { diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/ResetSourceCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/ResetSourceCmdlet.cs index ccac067979..be667df2f8 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/ResetSourceCmdlet.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/ResetSourceCmdlet.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. Licensed under the MIT License. // @@ -13,25 +13,41 @@ namespace Microsoft.WinGet.Client.Cmdlets.Cmdlets /// /// Resets a source. Requires admin. /// - [Cmdlet(VerbsCommon.Reset, Constants.WinGetNouns.Source)] + [Cmdlet(VerbsCommon.Reset, Constants.WinGetNouns.Source, DefaultParameterSetName = Constants.DefaultSet)] public sealed class ResetSourceCmdlet : PSCmdlet { /// /// Gets or sets the name of the source to reset. /// [Parameter( + Position = 0, Mandatory = true, + ParameterSetName = Constants.DefaultSet, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] public string Name { get; set; } + /// + /// Gets or sets a value indicating whether to reset all sources. + /// + [Parameter(ParameterSetName = Constants.OptionalSet, ValueFromPipelineByPropertyName = true)] + public SwitchParameter All { get; set; } + /// /// Resets source. /// protected override void ProcessRecord() { var command = new CliCommand(this); - command.ResetSource(this.Name); + + if (!string.IsNullOrEmpty(this.Name)) + { + command.ResetSourceByName(this.Name); + } + else if (this.All) + { + command.ResetAllSources(); + } } } } diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Common/Constants.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Common/Constants.cs index 78b0d850fa..0f403a512f 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Common/Constants.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Common/Constants.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. Licensed under the MIT License. // @@ -30,7 +30,17 @@ internal static class Constants /// This parameter set indicates that a package was not provided via a parameter or the pipeline and it /// needs to be found by searching a package source. /// - public const string FoundSet = "FoundSet"; + public const string FoundSet = "FoundSet"; + + /// + /// This parameter set indicates the default parameters associated with a cmdlet. + /// + public const string DefaultSet = "DefaultSet"; + + /// + /// This parameter set indicates the optional parameters associated with a cmdlet. + /// + public const string OptionalSet = "OptionalSet"; /// /// Parameter set for an specific version parameter. diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Microsoft.WinGet.Client.Cmdlets.csproj b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Microsoft.WinGet.Client.Cmdlets.csproj index 7ee7922d13..faea6e8f56 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Microsoft.WinGet.Client.Cmdlets.csproj +++ b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Microsoft.WinGet.Client.Cmdlets.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/PowerShell/Microsoft.WinGet.Client.Engine/Commands/CliCommand.cs b/src/PowerShell/Microsoft.WinGet.Client.Engine/Commands/CliCommand.cs index 452e36b447..5a1390e020 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Engine/Commands/CliCommand.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Engine/Commands/CliCommand.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. Licensed under the MIT License. // @@ -94,15 +94,24 @@ public void RemoveSource(string name) } /// - /// Resets source. + /// Resets a source. /// /// Name of source. - public void ResetSource(string name) + public void ResetSourceByName(string name) { Utilities.VerifyAdmin(); _ = this.Run("source", $"reset --name {name} --force"); } + /// + /// Resets all sources and adds the defaults. + /// + public void ResetAllSources() + { + Utilities.VerifyAdmin(); + _ = this.Run("source", $"reset --force"); + } + private WinGetCLICommandResult Run(string command, string parameters, int timeOut = 60000) { var wingetCliWrapper = new WingetCLIWrapper(); diff --git a/src/PowerShell/Microsoft.WinGet.Client.Engine/Helpers/GitHubClient.cs b/src/PowerShell/Microsoft.WinGet.Client.Engine/Helpers/GitHubClient.cs index a7cc18c1b6..be2eddd2ec 100644 --- a/src/PowerShell/Microsoft.WinGet.Client.Engine/Helpers/GitHubClient.cs +++ b/src/PowerShell/Microsoft.WinGet.Client.Engine/Helpers/GitHubClient.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. Licensed under the MIT License. // @@ -43,24 +43,24 @@ public async Task GetReleaseAsync(string releaseTag) /// /// Gets the latest released and waits. /// - /// Include prerelease. + /// Include prerelease. /// Latest version. - public async Task GetLatestReleaseTagNameAsync(bool includePreRelease) + public async Task GetLatestReleaseTagNameAsync(bool includePrerelease) { - return (await this.GetLatestReleaseAsync(includePreRelease)).TagName; + return (await this.GetLatestReleaseAsync(includePrerelease)).TagName; } /// /// Gets the latest released version. /// - /// Include prerelease. + /// Include prerelease. /// Latest version. - public async Task GetLatestReleaseAsync(bool includePreRelease) + public async Task GetLatestReleaseAsync(bool includePrerelease) { Release release; // GetLatest doesn't respect prerelease or gives an option to get it. - if (includePreRelease) + if (includePrerelease) { // GetAll orders by newest and includes pre releases. release = (await this.gitHubClient.Repository.Release.GetAll(this.owner, this.repo))[0]; diff --git a/src/PowerShell/Microsoft.WinGet.DSC/Microsoft.WinGet.DSC.psm1 b/src/PowerShell/Microsoft.WinGet.DSC/Microsoft.WinGet.DSC.psm1 index 0a5d8ddebd..f6e7602a2b 100644 --- a/src/PowerShell/Microsoft.WinGet.DSC/Microsoft.WinGet.DSC.psm1 +++ b/src/PowerShell/Microsoft.WinGet.DSC/Microsoft.WinGet.DSC.psm1 @@ -366,7 +366,7 @@ class WinGetPackageManager } elseif ($this.UseLatestPreRelease) { $hashArgs.Add("Latest", $true) - $hashArgs.Add("IncludePreRelease", $true) + $hashArgs.Add("IncludePrerelease", $true) } elseif (-not [string]::IsNullOrWhiteSpace($this.Version)) { $hashArgs.Add("Version", $this.Version) @@ -398,7 +398,7 @@ class WinGetPackageManager } elseif ($this.UseLatestPreRelease) { $hashArgs.Add("Latest", $true) - $hashArgs.Add("IncludePreRelease", $true) + $hashArgs.Add("IncludePrerelease", $true) } elseif (-not [string]::IsNullOrWhiteSpace($this.Version)) { $hashArgs.Add("Version", $this.Version) diff --git a/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 b/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 index 46f9603586..37cc959b45 100644 --- a/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 +++ b/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 @@ -136,6 +136,21 @@ Describe 'Get-WinGetVersion' { } } +Describe 'Reset-WinGetSource' { + BeforeAll { + AddTestSource + } + + # Requires admin + It 'Resets all sources' { + Reset-WinGetSource -All + } + + It 'Test source should be removed' { + { Get-WinGetSource -Name 'TestSource' } | Should -Throw + } +} + Describe 'Get|Add|Reset-WinGetSource' { BeforeAll {