winget-cli

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

UninstallPackageCmdlet.cs (2886B)


      1 // -----------------------------------------------------------------------------
      2 // <copyright file="UninstallPackageCmdlet.cs" company="Microsoft Corporation">
      3 //     Copyright (c) Microsoft Corporation. Licensed under the MIT License.
      4 // </copyright>
      5 // -----------------------------------------------------------------------------
      6 
      7 namespace Microsoft.WinGet.Client.Commands
      8 {
      9     using System.Management.Automation;
     10     using Microsoft.WinGet.Client.Commands.Common;
     11     using Microsoft.WinGet.Client.Common;
     12     using Microsoft.WinGet.Client.Engine.Commands;
     13     using Microsoft.WinGet.Client.Engine.PSObjects;
     14     using Microsoft.WinGet.Client.PSObjects;
     15 
     16     /// <summary>
     17     /// Uninstalls a package from the local system.
     18     /// </summary>
     19     [Cmdlet(
     20         VerbsLifecycle.Uninstall,
     21         Constants.WinGetNouns.Package,
     22         DefaultParameterSetName = Constants.FoundSet,
     23         SupportsShouldProcess = true)]
     24     [Alias("uswgp")]
     25     [OutputType(typeof(PSUninstallResult))]
     26     public sealed class UninstallPackageCmdlet : PackageCmdlet
     27     {
     28         private UninstallPackageCommand command = null;
     29 
     30         /// <summary>
     31         /// Gets or sets the desired mode for the uninstallation process.
     32         /// </summary>
     33         [Parameter(ValueFromPipelineByPropertyName = true)]
     34         public PSPackageUninstallMode Mode { get; set; } = PSPackageUninstallMode.Default;
     35 
     36         /// <summary>
     37         /// Gets or sets a value indicating whether to continue upon non security related failures.
     38         /// </summary>
     39         [Parameter(ValueFromPipelineByPropertyName = true)]
     40         public SwitchParameter Force { get; set; }
     41 
     42         /// <summary>
     43         /// Gets or sets the path to the logging file.
     44         /// </summary>
     45         [Parameter(ValueFromPipelineByPropertyName = true)]
     46         public string Log { get; set; }
     47 
     48         /// <summary>
     49         /// Uninstalls a package from the local system.
     50         /// </summary>
     51         protected override void ProcessRecord()
     52         {
     53             this.command = new UninstallPackageCommand(
     54                         this,
     55                         this.PSCatalogPackage,
     56                         this.Version,
     57                         this.Log,
     58                         this.Id,
     59                         this.Name,
     60                         this.Moniker,
     61                         this.Source,
     62                         this.Query);
     63             this.command.Uninstall(this.MatchOption.ToString(), this.Mode.ToString(), this.Force.ToBool());
     64         }
     65 
     66         /// <summary>
     67         /// Interrupts currently running code within the command.
     68         /// </summary>
     69         protected override void StopProcessing()
     70         {
     71             if (this.command != null)
     72             {
     73                 this.command.Cancel();
     74             }
     75         }
     76     }
     77 }