Skip to content

Commit 93c0f88

Browse files
authored
Install should implement ShouldProcess (#425)
* Install should impelement ShouldProcess
1 parent ab68832 commit 93c0f88

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/code/InstallPSResource.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Collections.Specialized;
12
// Copyright (c) Microsoft Corporation. All rights reserved.
23
// Licensed under the MIT License.
34
using System;
@@ -15,7 +16,7 @@ namespace Microsoft.PowerShell.PowerShellGet.Cmdlets
1516
/// It returns nothing.
1617
/// </summary>
1718

18-
[Cmdlet(VerbsLifecycle.Install, "PSResource", DefaultParameterSetName = "NameParameterSet", SupportsShouldProcess = true, HelpUri = "<add>")]
19+
[Cmdlet(VerbsLifecycle.Install, "PSResource", DefaultParameterSetName = "NameParameterSet", SupportsShouldProcess = true)]
1920
public sealed
2021
class InstallPSResource : PSCmdlet
2122
{
@@ -124,6 +125,12 @@ protected override void BeginProcessing()
124125

125126
protected override void ProcessRecord()
126127
{
128+
if (!ShouldProcess(string.Format("package to install: '{0}'", String.Join(", ", Name))))
129+
{
130+
WriteVerbose(string.Format("Install operation cancelled by user for packages: {0}", String.Join(", ", Name)));
131+
return;
132+
}
133+
127134
var installHelper = new InstallHelper(updatePkg: false, savePkg: false, cmdletPassedIn: this);
128135

129136
switch (ParameterSetName)

test/InstallPSResource.Tests.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ Describe 'Test Install-PSResource for Module' {
226226
$pkg | Should -Not -BeNullOrEmpty
227227
$pkg.Name | Should -Be $publishModuleName
228228
}
229+
230+
It "Install module using -WhatIf, should not install the module" {
231+
Install-PSResource -Name "TestModule" -WhatIf
232+
233+
$res = Get-Module "TestModule" -ListAvailable
234+
$res | Should -BeNullOrEmpty
235+
}
229236
}
230237

231238
<# Temporarily commented until -Tag is implemented for this Describe block

0 commit comments

Comments
 (0)