-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new cmdlets and cancellation support for Microsoft.WinGet.Configu…
…ration (#3614) Test-WinGetConfiguration to test a configuration. Equivalent of winget configure test Confirm-WinGetConfiguration to validate a configuration. Equivalent of winget configure validate except it just calls the configuration APIs without the extra validation winget does. Support cancellation via CTRL-C for blocking cmdlets and Stop-WinGetConfiguration for configuration stated with Start-WinGetConfiguration Add tests for Test-WinGetConfiguration and Confirm-WinGetConfiguration cmdlets. Add more tests for Open-WinGetConfiguration Cancellation verified manually
- Loading branch information
1 parent
157d768
commit c307ab6
Showing
22 changed files
with
902 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...rShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/ConfirmWinGetConfigurationCmdlet.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// ----------------------------------------------------------------------------- | ||
// <copyright file="ConfirmWinGetConfigurationCmdlet.cs" company="Microsoft Corporation"> | ||
// Copyright (c) Microsoft Corporation. Licensed under the MIT License. | ||
// </copyright> | ||
// ----------------------------------------------------------------------------- | ||
|
||
namespace Microsoft.WinGet.Configuration.Cmdlets | ||
{ | ||
using System.Management.Automation; | ||
using Microsoft.WinGet.Configuration.Engine.Commands; | ||
using Microsoft.WinGet.Configuration.Engine.PSObjects; | ||
|
||
/// <summary> | ||
/// Confirm-WinGetConfiguration | ||
/// Validates winget configuration. | ||
/// </summary> | ||
[Cmdlet(VerbsLifecycle.Confirm, "WinGetConfiguration")] | ||
public class ConfirmWinGetConfigurationCmdlet : PSCmdlet | ||
{ | ||
private ConfigurationCommand runningCommand = null; | ||
|
||
/// <summary> | ||
/// Gets or sets the configuration set. | ||
/// </summary> | ||
[Parameter( | ||
Position = 0, | ||
Mandatory = true, | ||
ValueFromPipeline = true, | ||
ValueFromPipelineByPropertyName = true)] | ||
public PSConfigurationSet Set { get; set; } | ||
|
||
/// <summary> | ||
/// Validate configuration. | ||
/// </summary> | ||
protected override void ProcessRecord() | ||
{ | ||
this.runningCommand = new ConfigurationCommand(this); | ||
this.runningCommand.Validate(this.Set); | ||
} | ||
|
||
/// <summary> | ||
/// Interrupts currently running code within the command. | ||
/// </summary> | ||
protected override void StopProcessing() | ||
{ | ||
if (this.runningCommand != null) | ||
{ | ||
this.runningCommand.Cancel(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...owerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/StopWinGetConfigurationCmdlet.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// ----------------------------------------------------------------------------- | ||
// <copyright file="StopWinGetConfigurationCmdlet.cs" company="Microsoft Corporation"> | ||
// Copyright (c) Microsoft Corporation. Licensed under the MIT License. | ||
// </copyright> | ||
// ----------------------------------------------------------------------------- | ||
|
||
namespace Microsoft.WinGet.Configuration.Cmdlets | ||
{ | ||
using System.Management.Automation; | ||
using Microsoft.WinGet.Configuration.Engine.Commands; | ||
using Microsoft.WinGet.Configuration.Engine.PSObjects; | ||
|
||
/// <summary> | ||
/// Stop-WinGetConfiguration. | ||
/// Cancels a configuration previously started by Start-WinGetConfiguration. | ||
/// </summary> | ||
[Cmdlet(VerbsLifecycle.Stop, "WinGetConfiguration")] | ||
public sealed class StopWinGetConfigurationCmdlet : PSCmdlet | ||
{ | ||
/// <summary> | ||
/// Gets or sets the configuration task. | ||
/// </summary> | ||
[Parameter( | ||
Position = 0, | ||
Mandatory = true, | ||
ValueFromPipeline = true, | ||
ValueFromPipelineByPropertyName = true)] | ||
public PSConfigurationJob ConfigurationJob { get; set; } | ||
|
||
/// <summary> | ||
/// Starts to apply the configuration and wait for it to complete. | ||
/// </summary> | ||
protected override void ProcessRecord() | ||
{ | ||
var configCommand = new ConfigurationCommand(this); | ||
configCommand.Cancel(this.ConfigurationJob); | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...owerShell/Microsoft.WinGet.Configuration.Cmdlets/Cmdlets/TestWinGetConfigurationCmdlet.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// ----------------------------------------------------------------------------- | ||
// <copyright file="TestWinGetConfigurationCmdlet.cs" company="Microsoft Corporation"> | ||
// Copyright (c) Microsoft Corporation. Licensed under the MIT License. | ||
// </copyright> | ||
// ----------------------------------------------------------------------------- | ||
|
||
namespace Microsoft.WinGet.Configuration.Cmdlets | ||
{ | ||
using System.Management.Automation; | ||
using Microsoft.WinGet.Configuration.Engine.Commands; | ||
using Microsoft.WinGet.Configuration.Engine.PSObjects; | ||
|
||
/// <summary> | ||
/// Test-WinGetConfiguration | ||
/// Tests configuration. | ||
/// </summary> | ||
[Cmdlet(VerbsDiagnostic.Test, "WinGetConfiguration")] | ||
public class TestWinGetConfigurationCmdlet : PSCmdlet | ||
{ | ||
private bool acceptedAgreements = false; | ||
private ConfigurationCommand runningCommand = null; | ||
|
||
/// <summary> | ||
/// Gets or sets the configuration set. | ||
/// </summary> | ||
[Parameter( | ||
Position = 0, | ||
Mandatory = true, | ||
ValueFromPipeline = true, | ||
ValueFromPipelineByPropertyName = true)] | ||
public PSConfigurationSet Set { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether to accept the configuration agreements. | ||
/// </summary> | ||
[Parameter(ValueFromPipelineByPropertyName = true)] | ||
public SwitchParameter AcceptConfigurationAgreements { get; set; } | ||
|
||
/// <summary> | ||
/// Pre-processing operations. | ||
/// </summary> | ||
protected override void BeginProcessing() | ||
{ | ||
this.acceptedAgreements = ConfigurationCommand.ConfirmConfigurationProcessing(this, this.AcceptConfigurationAgreements.ToBool(), false); | ||
} | ||
|
||
/// <summary> | ||
/// Test configuration. | ||
/// </summary> | ||
protected override void ProcessRecord() | ||
{ | ||
if (this.acceptedAgreements) | ||
{ | ||
this.runningCommand = new ConfigurationCommand(this); | ||
this.runningCommand.Test(this.Set); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Interrupts currently running code within the command. | ||
/// </summary> | ||
protected override void StopProcessing() | ||
{ | ||
if (this.runningCommand != null) | ||
{ | ||
this.runningCommand.Cancel(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.