Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/code/InstallPSResource.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Specialized;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
Expand All @@ -15,7 +16,7 @@ namespace Microsoft.PowerShell.PowerShellGet.Cmdlets
/// It returns nothing.
/// </summary>

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

protected override void ProcessRecord()
{
if (!ShouldProcess(string.Format("package to install: '{0}'", String.Join(", ", Name))))
{
WriteVerbose(string.Format("Install operation cancelled by user for packages: {0}", String.Join(", ", Name)));
return;
}

var installHelper = new InstallHelper(updatePkg: false, savePkg: false, cmdletPassedIn: this);

switch (ParameterSetName)
Expand Down
7 changes: 7 additions & 0 deletions test/InstallPSResource.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ Describe 'Test Install-PSResource for Module' {
$pkg | Should -Not -BeNullOrEmpty
$pkg.Name | Should -Be $publishModuleName
}

It "Install module using -WhatIf, should not install the module" {
Install-PSResource -Name "TestModule" -WhatIf

$res = Get-Module "TestModule" -ListAvailable
$res | Should -BeNullOrEmpty
}
}

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