InstallPackageCmdlet.cs (2509B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="InstallPackageCmdlet.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 15 /// <summary> 16 /// Installs a package from the pipeline or from a configured source. 17 /// </summary> 18 [Cmdlet( 19 VerbsLifecycle.Install, 20 Constants.WinGetNouns.Package, 21 DefaultParameterSetName = Constants.FoundSet, 22 SupportsShouldProcess = true)] 23 [Alias("iswgp")] 24 [OutputType(typeof(PSInstallResult))] 25 public sealed class InstallPackageCmdlet : InstallCmdlet 26 { 27 private InstallerPackageCommand command = null; 28 29 /// <summary> 30 /// Installs a package from the pipeline or from a configured source. 31 /// </summary> 32 protected override void ProcessRecord() 33 { 34 this.command = new InstallerPackageCommand( 35 this, 36 this.Override, 37 this.Custom, 38 this.Location, 39 this.AllowHashMismatch.ToBool(), 40 this.Force.ToBool(), 41 this.Header, 42 this.PSCatalogPackage, 43 this.Version, 44 this.Log, 45 this.Id, 46 this.Name, 47 this.Moniker, 48 this.Source, 49 this.Query, 50 this.SkipDependencies.ToBool()); 51 52 this.command.Install(this.MatchOption.ToString(), this.Scope.ToString(), this.Architecture.ToString(), this.Mode.ToString(), this.InstallerType.ToString()); 53 } 54 55 /// <summary> 56 /// Interrupts currently running code within the command. 57 /// </summary> 58 protected override void StopProcessing() 59 { 60 if (this.command != null) 61 { 62 this.command.Cancel(); 63 } 64 } 65 } 66 }