Skip to content

Commit 83b2db4

Browse files
authored
Fix Reset-WinGetSource behavior (#4732)
1 parent 7723804 commit 83b2db4

13 files changed

+112
-29
lines changed

src/PowerShell/Help/Microsoft.WinGet.Client/Assert-WinGetPackageManager.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Assert-WinGetPackageManager [-Version <String>] [<CommonParameters>]
2323
### IntegrityLatestSet
2424

2525
```
26-
Assert-WinGetPackageManager [-Latest] [-IncludePreRelease] [<CommonParameters>]
26+
Assert-WinGetPackageManager [-Latest] [-IncludePrerelease] [<CommonParameters>]
2727
```
2828

2929
## DESCRIPTION

src/PowerShell/Help/Microsoft.WinGet.Client/Reset-WinGetSource.md

+36-4
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,26 @@ title: Reset-WinGetSource
1010
# Reset-WinGetSource
1111

1212
## SYNOPSIS
13-
Resets default WinGet sources.
13+
Resets WinGet sources.
1414

1515
## SYNTAX
1616

17+
### DefaultSet (Default)
18+
1719
```
1820
Reset-WinGetSource -Name <String> [<CommonParameters>]
1921
```
2022

23+
### OptionalSet
24+
25+
```
26+
Reset-WinGetSource -All [<CommonParameters>]
27+
```
28+
2129
## DESCRIPTION
2230

23-
Resets the current WinGet sources to the default source configurations. This command must be
24-
executed with administrator permissions.
31+
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.
32+
This command must be executed with administrator permissions.
2533

2634
## EXAMPLES
2735

@@ -33,15 +41,39 @@ Reset-WinGetSource -Name msstore
3341

3442
This example resets the configured source named 'msstore' by removing it.
3543

44+
### Example 2: Reset all sources
45+
46+
```powershell
47+
Reset-WinGetSource -All
48+
```
49+
50+
This example resets all configured sources and adds the default sources.
51+
3652
## PARAMETERS
3753

54+
### -All
55+
56+
Reset all sources and add the default sources.
57+
58+
```yaml
59+
Type: System.Management.Automation.SwitchParameter
60+
Parameter Sets: (OptionalSet)
61+
Aliases:
62+
63+
Required: False
64+
Position: Named
65+
Default value: None
66+
Accept pipeline input: True (ByPropertyName)
67+
Accept wildcard characters: False
68+
```
69+
3870
### -Name
3971
4072
The name of the source.
4173
4274
```yaml
4375
Type: System.String
44-
Parameter Sets: (All)
76+
Parameter Sets: (DefaultSet)
4577
Aliases:
4678

4779
Required: True

src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/AssertWinGetPackageManagerCmdlet.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// -----------------------------------------------------------------------------
1+
// -----------------------------------------------------------------------------
22
// <copyright file="AssertWinGetPackageManagerCmdlet.cs" company="Microsoft Corporation">
33
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
44
// </copyright>
@@ -29,7 +29,7 @@ protected override void ProcessRecord()
2929
var command = new WinGetPackageManagerCommand(this);
3030
if (this.ParameterSetName == Constants.IntegrityLatestSet)
3131
{
32-
command.AssertUsingLatest(this.IncludePreRelease.ToBool());
32+
command.AssertUsingLatest(this.IncludePrerelease.ToBool());
3333
}
3434
else
3535
{

src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/Common/WinGetPackageManagerCmdlet.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// -----------------------------------------------------------------------------
1+
// -----------------------------------------------------------------------------
22
// <copyright file="WinGetPackageManagerCmdlet.cs" company="Microsoft Corporation">
33
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
44
// </copyright>
@@ -36,6 +36,6 @@ public abstract class WinGetPackageManagerCmdlet : PSCmdlet
3636
[Parameter(
3737
ParameterSetName = Constants.IntegrityLatestSet,
3838
ValueFromPipelineByPropertyName = true)]
39-
public SwitchParameter IncludePreRelease { get; set; }
39+
public SwitchParameter IncludePrerelease { get; set; }
4040
}
4141
}

src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/RemoveSourceCmdlet.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// -----------------------------------------------------------------------------
1+
// -----------------------------------------------------------------------------
22
// <copyright file="RemoveSourceCmdlet.cs" company="Microsoft Corporation">
33
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
44
// </copyright>
@@ -20,6 +20,7 @@ public sealed class RemoveSourceCmdlet : PSCmdlet
2020
/// Gets or sets the name of the source to remove.
2121
/// </summary>
2222
[Parameter(
23+
Position = 0,
2324
Mandatory = true,
2425
ValueFromPipeline = true,
2526
ValueFromPipelineByPropertyName = true)]

src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/RepairWinGetPackageManagerCmdlet.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected override void ProcessRecord()
4444
this.command = new WinGetPackageManagerCommand(this);
4545
if (this.ParameterSetName == Constants.IntegrityLatestSet)
4646
{
47-
this.command.RepairUsingLatest(this.IncludePreRelease.ToBool(), this.AllUsers.ToBool(), this.Force.ToBool());
47+
this.command.RepairUsingLatest(this.IncludePrerelease.ToBool(), this.AllUsers.ToBool(), this.Force.ToBool());
4848
}
4949
else
5050
{

src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/ResetSourceCmdlet.cs

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// -----------------------------------------------------------------------------
1+
// -----------------------------------------------------------------------------
22
// <copyright file="ResetSourceCmdlet.cs" company="Microsoft Corporation">
33
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
44
// </copyright>
@@ -13,25 +13,41 @@ namespace Microsoft.WinGet.Client.Cmdlets.Cmdlets
1313
/// <summary>
1414
/// Resets a source. Requires admin.
1515
/// </summary>
16-
[Cmdlet(VerbsCommon.Reset, Constants.WinGetNouns.Source)]
16+
[Cmdlet(VerbsCommon.Reset, Constants.WinGetNouns.Source, DefaultParameterSetName = Constants.DefaultSet)]
1717
public sealed class ResetSourceCmdlet : PSCmdlet
1818
{
1919
/// <summary>
2020
/// Gets or sets the name of the source to reset.
2121
/// </summary>
2222
[Parameter(
23+
Position = 0,
2324
Mandatory = true,
25+
ParameterSetName = Constants.DefaultSet,
2426
ValueFromPipeline = true,
2527
ValueFromPipelineByPropertyName = true)]
2628
public string Name { get; set; }
2729

30+
/// <summary>
31+
/// Gets or sets a value indicating whether to reset all sources.
32+
/// </summary>
33+
[Parameter(ParameterSetName = Constants.OptionalSet, ValueFromPipelineByPropertyName = true)]
34+
public SwitchParameter All { get; set; }
35+
2836
/// <summary>
2937
/// Resets source.
3038
/// </summary>
3139
protected override void ProcessRecord()
3240
{
3341
var command = new CliCommand(this);
34-
command.ResetSource(this.Name);
42+
43+
if (!string.IsNullOrEmpty(this.Name))
44+
{
45+
command.ResetSourceByName(this.Name);
46+
}
47+
else if (this.All)
48+
{
49+
command.ResetAllSources();
50+
}
3551
}
3652
}
3753
}

src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Common/Constants.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// -----------------------------------------------------------------------------
1+
// -----------------------------------------------------------------------------
22
// <copyright file="Constants.cs" company="Microsoft Corporation">
33
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
44
// </copyright>
@@ -30,7 +30,17 @@ internal static class Constants
3030
/// This parameter set indicates that a package was not provided via a parameter or the pipeline and it
3131
/// needs to be found by searching a package source.
3232
/// </summary>
33-
public const string FoundSet = "FoundSet";
33+
public const string FoundSet = "FoundSet";
34+
35+
/// <summary>
36+
/// This parameter set indicates the default parameters associated with a cmdlet.
37+
/// </summary>
38+
public const string DefaultSet = "DefaultSet";
39+
40+
/// <summary>
41+
/// This parameter set indicates the optional parameters associated with a cmdlet.
42+
/// </summary>
43+
public const string OptionalSet = "OptionalSet";
3444

3545
/// <summary>
3646
/// Parameter set for an specific version parameter.

src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Microsoft.WinGet.Client.Cmdlets.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<!-- If these target frameworks are updated, make sure to also update the .psd1 and .nuspec files.-->

src/PowerShell/Microsoft.WinGet.Client.Engine/Commands/CliCommand.cs

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// -----------------------------------------------------------------------------
1+
// -----------------------------------------------------------------------------
22
// <copyright file="CliCommand.cs" company="Microsoft Corporation">
33
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
44
// </copyright>
@@ -94,15 +94,24 @@ public void RemoveSource(string name)
9494
}
9595

9696
/// <summary>
97-
/// Resets source.
97+
/// Resets a source.
9898
/// </summary>
9999
/// <param name="name">Name of source.</param>
100-
public void ResetSource(string name)
100+
public void ResetSourceByName(string name)
101101
{
102102
Utilities.VerifyAdmin();
103103
_ = this.Run("source", $"reset --name {name} --force");
104104
}
105105

106+
/// <summary>
107+
/// Resets all sources and adds the defaults.
108+
/// </summary>
109+
public void ResetAllSources()
110+
{
111+
Utilities.VerifyAdmin();
112+
_ = this.Run("source", $"reset --force");
113+
}
114+
106115
private WinGetCLICommandResult Run(string command, string parameters, int timeOut = 60000)
107116
{
108117
var wingetCliWrapper = new WingetCLIWrapper();

src/PowerShell/Microsoft.WinGet.Client.Engine/Helpers/GitHubClient.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// -----------------------------------------------------------------------------
1+
// -----------------------------------------------------------------------------
22
// <copyright file="GitHubClient.cs" company="Microsoft Corporation">
33
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
44
// </copyright>
@@ -43,24 +43,24 @@ public async Task<Release> GetReleaseAsync(string releaseTag)
4343
/// <summary>
4444
/// Gets the latest released and waits.
4545
/// </summary>
46-
/// <param name="includePreRelease">Include prerelease.</param>
46+
/// <param name="includePrerelease">Include prerelease.</param>
4747
/// <returns>Latest version.</returns>
48-
public async Task<string> GetLatestReleaseTagNameAsync(bool includePreRelease)
48+
public async Task<string> GetLatestReleaseTagNameAsync(bool includePrerelease)
4949
{
50-
return (await this.GetLatestReleaseAsync(includePreRelease)).TagName;
50+
return (await this.GetLatestReleaseAsync(includePrerelease)).TagName;
5151
}
5252

5353
/// <summary>
5454
/// Gets the latest released version.
5555
/// </summary>
56-
/// <param name="includePreRelease">Include prerelease.</param>
56+
/// <param name="includePrerelease">Include prerelease.</param>
5757
/// <returns>Latest version.</returns>
58-
public async Task<Release> GetLatestReleaseAsync(bool includePreRelease)
58+
public async Task<Release> GetLatestReleaseAsync(bool includePrerelease)
5959
{
6060
Release release;
6161

6262
// GetLatest doesn't respect prerelease or gives an option to get it.
63-
if (includePreRelease)
63+
if (includePrerelease)
6464
{
6565
// GetAll orders by newest and includes pre releases.
6666
release = (await this.gitHubClient.Repository.Release.GetAll(this.owner, this.repo))[0];

src/PowerShell/Microsoft.WinGet.DSC/Microsoft.WinGet.DSC.psm1

+2-2
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ class WinGetPackageManager
366366
} elseif ($this.UseLatestPreRelease)
367367
{
368368
$hashArgs.Add("Latest", $true)
369-
$hashArgs.Add("IncludePreRelease", $true)
369+
$hashArgs.Add("IncludePrerelease", $true)
370370
} elseif (-not [string]::IsNullOrWhiteSpace($this.Version))
371371
{
372372
$hashArgs.Add("Version", $this.Version)
@@ -398,7 +398,7 @@ class WinGetPackageManager
398398
} elseif ($this.UseLatestPreRelease)
399399
{
400400
$hashArgs.Add("Latest", $true)
401-
$hashArgs.Add("IncludePreRelease", $true)
401+
$hashArgs.Add("IncludePrerelease", $true)
402402
} elseif (-not [string]::IsNullOrWhiteSpace($this.Version))
403403
{
404404
$hashArgs.Add("Version", $this.Version)

src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1

+15
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,21 @@ Describe 'Get-WinGetVersion' {
136136
}
137137
}
138138

139+
Describe 'Reset-WinGetSource' {
140+
BeforeAll {
141+
AddTestSource
142+
}
143+
144+
# Requires admin
145+
It 'Resets all sources' {
146+
Reset-WinGetSource -All
147+
}
148+
149+
It 'Test source should be removed' {
150+
{ Get-WinGetSource -Name 'TestSource' } | Should -Throw
151+
}
152+
}
153+
139154
Describe 'Get|Add|Reset-WinGetSource' {
140155

141156
BeforeAll {

0 commit comments

Comments
 (0)