diff --git a/nuget/tools/chocolateysetup.psm1 b/nuget/tools/chocolateysetup.psm1 index 25a253a..3059522 100644 --- a/nuget/tools/chocolateysetup.psm1 +++ b/nuget/tools/chocolateysetup.psm1 @@ -35,6 +35,7 @@ $nugetChocolateyUpdateAlias = Join-Path $chocolateyExePath 'cup.bat' $nugetChocolateyListAlias = Join-Path $chocolateyExePath 'clist.bat' $nugetChocolateyVersionAlias = Join-Path $chocolateyExePath 'cver.bat' $nugetChocolateyWebPiAlias = Join-Path $chocolateyExePath 'cwebpi.bat' +$nugetChocolateyWindowsFeaturesAlias = Join-Path $chocolateyExePath 'cwindowsfeatures.bat' $nugetChocolateyCygwinAlias = Join-Path $chocolateyExePath 'ccygwin.bat' $nugetChocolateyPythonAlias = Join-Path $chocolateyExePath 'cpython.bat' $nugetChocolateyGemAlias = Join-Path $chocolateyExePath 'cgem.bat' @@ -78,6 +79,11 @@ Write-Host "Creating `'$nugetChocolateyWebPiAlias`' so you can call 'chocolatey SET DIR=%~dp0% ""$nugetChocolateyPath\chocolatey.cmd"" webpi %*" | Out-File $nugetChocolateyWebPiAlias -encoding ASCII +Write-Host "Creating `'$nugetChocolateyWindowsFeaturesAlias`' so you can call 'chocolatey windowsfeatures' from a shortcut of 'cwinfeatures'." +"@echo off +SET DIR=%~dp0% +""$nugetChocolateyPath\chocolatey.cmd"" windowsfeatures %*" | Out-File $nugetChocolateyWindowsFeaturesAlias -encoding ASCII + Write-Host "Creating `'$nugetChocolateyCygwinAlias`' so you can call 'chocolatey cygwin' from a shortcut of 'ccygwin'." "@echo off SET DIR=%~dp0% diff --git a/src/chocolatey.ps1 b/src/chocolatey.ps1 index 6976731..cebf522 100644 --- a/src/chocolatey.ps1 +++ b/src/chocolatey.ps1 @@ -75,6 +75,7 @@ switch -wildcard ($command) "list" { Chocolatey-List $packageName $source; } "version" { Chocolatey-Version $packageName $source; } "webpi" { Chocolatey-WebPI $packageName $installArguments; } + "windowsfeatures" { Chocolatey-WindowsFeatures $packageName; } "cygwin" { Chocolatey-Cygwin $packageName $installArguments; } "python" { Chocolatey-Python $packageName $version $installArguments; } "gem" { Chocolatey-RubyGem $packageName $version $installArguments; } diff --git a/src/functions/Chocolatey-Help.ps1 b/src/functions/Chocolatey-Help.ps1 index 8286c70..af26cfa 100644 --- a/src/functions/Chocolatey-Help.ps1 +++ b/src/functions/Chocolatey-Help.ps1 @@ -48,14 +48,14 @@ Waiver of Responsibility $h2 The use of chocolatey means that an individual using chocolatey assumes the responsibility for any changes (including any damages of any sort) that occur to the system as a result of using chocolatey. This does not supercede the verbage or enforcement of the license for chocolatey (currently Apache 2.0), it is only noted here that you are waiving any rights to collect damages by your use of chocolatey. -It is recommended you read the license (http://www.apache.org/licenses/LICENSE-2.0) to gain a full understanding (especially section 8. Limitation of Liability) prior to using chocolatey. +It is recommended you read the license (http://www.apache.org/licenses/LICENSE-2.0) to gain a full understanding (especially section 8. Limitation of Liability) prior to using chocolatey. $h2 } $h2 $h2 Usage $h2 -chocolatey [install [packageName [-source source] [-version version] | pathToPackagesConfig] | installmissing packageName [-source source] | update packageName [-source source] [-version version] | list [packageName] [-source source] | help | version [packageName] | webpi packageName | gem packageName [-version version] |uninstall packageName] +chocolatey [install [packageName [-source source] [-version version] | pathToPackagesConfig] | installmissing packageName [-source source] | update packageName [-source source] [-version version] | list [packageName] [-source source] | help | version [packageName] | webpi packageName | windowsfeatures packageName | gem packageName [-version version] |uninstall packageName] example: chocolatey install nunit example: chocolatey install nunit -version 2.5.7.10213 diff --git a/src/functions/Chocolatey-Install.ps1 b/src/functions/Chocolatey-Install.ps1 index 8393a03..ea3baca 100644 --- a/src/functions/Chocolatey-Install.ps1 +++ b/src/functions/Chocolatey-Install.ps1 @@ -16,6 +16,7 @@ param( switch -wildcard ($source) { "webpi" { Chocolatey-WebPI $packageName $installerArguments; } + "windowsfeatures" { Chocolatey-WindowsFeatures $packageName; } "cygwin" { Chocolatey-Cygwin $packageName $installerArguments; } "python" { Chocolatey-Python $packageName $version $installerArguments; } "ruby" { Chocolatey-RubyGem $packageName $version $installerArguments; } diff --git a/src/functions/Chocolatey-List.ps1 b/src/functions/Chocolatey-List.ps1 index 67c2ecc..da3244b 100644 --- a/src/functions/Chocolatey-List.ps1 +++ b/src/functions/Chocolatey-List.ps1 @@ -8,6 +8,16 @@ param( if ($source -like 'webpi') { $webpiArgs ="/c webpicmd /List /ListOption:All" & cmd.exe $webpiArgs + } elseif ($source -like 'windowsfeatures') { + $chocoInstallLog = Join-Path $nugetChocolateyPath 'chocolateyWindowsFeaturesInstall.log'; + Remove-LastInstallLog $chocoInstallLog + $windowsFeaturesArgs ="/c dism /online /get-features /format:table | Tee-Object -FilePath `'$chocoInstallLog`';" + Start-ChocolateyProcessAsAdmin "cmd.exe $windowsFeaturesArgs" -nosleep + Create-InstallLogIfNotExists $chocoInstallLog + $installOutput = Get-Content $chocoInstallLog -Encoding Ascii + foreach ($line in $installOutput) { + Write-Host $line + } } else { $srcArgs = Get-SourceArguments $source diff --git a/src/functions/Chocolatey-WindowsFeatures.ps1 b/src/functions/Chocolatey-WindowsFeatures.ps1 new file mode 100644 index 0000000..ee8778c --- /dev/null +++ b/src/functions/Chocolatey-WindowsFeatures.ps1 @@ -0,0 +1,38 @@ +function Chocolatey-WindowsFeatures { +param( + [string] $packageName +) + Write-Debug "Running 'Chocolatey-WindowsFeatures' for $packageName"; + +@" +$h1 +Chocolatey ($chocVer) is installing `'$packageName`' (from Windows Veatures).. +$h1 +"@ | Write-Host + + $chocoInstallLog = Join-Path $nugetChocolateyPath 'chocolateyWindowsFeaturesInstall.log'; + Remove-LastInstallLog $chocoInstallLog + $osVersion = (Get-WmiObject -class Win32_OperatingSystem).Version + + $packageArgs = "/c DISM /Online /NoRestart /Enable-Feature" + if($osVersion -ge 6.2) { + $packageArgs += " /all" + } + $packageArgs += " /FeatureName:$packageName" + + Write-Host "Opening minimized PowerShell window and calling `'cmd.exe $packageArgs`'. If progress is taking a long time, please check that window. It also may not be 100% silent..." + $statements = "cmd.exe $packageArgs | Tee-Object -FilePath `'$chocoInstallLog`';" + Start-ChocolateyProcessAsAdmin "$statements" -minimized -nosleep -validExitCodes @(0,1) + + Create-InstallLogIfNotExists $chocoInstallLog + $installOutput = Get-Content $chocoInstallLog -Encoding Ascii + foreach ($line in $installOutput) { + Write-Host $line + } + +@" +$h1 +Chocolatey has finished installing `'$packageName`' - check log for errors. +$h1 +"@ | Write-Host +} \ No newline at end of file diff --git a/tests/_FunctionRenameActuals.ps1 b/tests/_FunctionRenameActuals.ps1 index 55894cd..9722a2f 100644 --- a/tests/_FunctionRenameActuals.ps1 +++ b/tests/_FunctionRenameActuals.ps1 @@ -13,6 +13,7 @@ rename-item function:Chocolatey-RubyGem Chocolatey-RubyGem-Actual rename-item function:Chocolatey-Update Chocolatey-Update-Actual rename-item function:Chocolatey-Version Chocolatey-Version-Actual rename-item function:Chocolatey-WebPI Chocolatey-WebPI-Actual +rename-item function:Chocolatey-WindowsFeatures Chocolatey-WindowsFeatures-Actual rename-item function:Chocolatey-Cygwin Chocolatey-Cygwin-Actual rename-item function:Delete-ExistingErrorLog Delete-ExistingErrorLog-Actual rename-item function:Generate-BinFile Generate-BinFile-Actual diff --git a/tests/_Initialize-Variables.ps1 b/tests/_Initialize-Variables.ps1 index 3f46272..08edc52 100644 --- a/tests/_Initialize-Variables.ps1 +++ b/tests/_Initialize-Variables.ps1 @@ -32,6 +32,7 @@ $script:chocolatey_update_was_called = $false $script:chocolatey_version_was_called = $false $script:chocolatey_webpi_was_called = $false + $script:chocolatey_windowsfeatures_was_called = $false $script:chocolatey_cygwin_was_called = $false $script:delete_existingerrorlog_was_called = $false $script:generate_binfile_was_called = $false @@ -74,6 +75,7 @@ $script:chocolatey_update_return_value = '' $script:chocolatey_version_return_value = '' $script:chocolatey_webpi_return_value = '' + $script:chocolatey_windowsfeatures_return_value = '' $script:chocolatey_cygwin_return_value = '' $script:delete_existingerrorlog_return_value = '' $script:generate_binfile_return_value = '' @@ -116,6 +118,7 @@ $script:exec_chocolatey_update_actual = $false $script:exec_chocolatey_version_actual = $false $script:exec_chocolatey_webpi_actual = $false + $script:exec_chocolatey_windowsfeatures_actual = $false $script:exec_chocolatey_cygwin_actual = $false $script:exec_delete_existingerrorlog_actual = $false $script:exec_generate_binfile_actual = $false diff --git a/tests/_Setup.ps1 b/tests/_Setup.ps1 index bc0b04c..8bc32af 100644 --- a/tests/_Setup.ps1 +++ b/tests/_Setup.ps1 @@ -3,6 +3,7 @@ Setup -File 'chocolatey\lib\_crapworkaround.txt' Setup -File 'chocolatey\bin\_crapworkaround.txt' Setup -File 'chocolatey\chocolateyInstall\chocolateyInstall.log' Setup -File 'chocolatey\chocolateyInstall\chocolateyWebPiInstall.log' +Setup -File 'chocolatey\chocolateyInstall\chocolateyWindowsFeaturesInstall.log' Setup -File 'chocolatey\chocolateyInstall\chocolateyCygwinInstall.log' Setup -File 'chocolatey\chocolateyInstall\error.log' Setup -File 'chocolatey\chocolateyInstall\install.log' diff --git a/tests/functions/Chocolatey-WindowsFeatures.ps1 b/tests/functions/Chocolatey-WindowsFeatures.ps1 new file mode 100644 index 0000000..3d49afc --- /dev/null +++ b/tests/functions/Chocolatey-WindowsFeatures.ps1 @@ -0,0 +1,9 @@ +function Chocolatey-WindowsFeatures { +param( + [string] $packageName +) + $script:chocolatey_windowsfeatures_was_called = $true + $script:packageName = $packageName + + if ($script:exec_chocolatey_windowsfeatures_actual) { Chocolatey-WindowsFeatures-Actual @PSBoundParameters} +} \ No newline at end of file diff --git a/tests/unit/Chocolatey-Install.tests.ps1 b/tests/unit/Chocolatey-Install.tests.ps1 index f4db461..7a9e990 100644 --- a/tests/unit/Chocolatey-Install.tests.ps1 +++ b/tests/unit/Chocolatey-Install.tests.ps1 @@ -54,6 +54,10 @@ Describe "When calling Chocolatey-Install normally" { $script:chocolatey_webpi_was_called.should.be($false) } + It "should not call Chocolatey-WindowsFeatures" { + $script:chocolatey_windowsfeatures_was_called.should.be($false) + } + It "should not call Chocolatey-RubyGem" { $script:chocolatey_rubygem_was_called.should.be($false) } @@ -77,6 +81,10 @@ Describe "When calling Chocolatey-Install with .config in the name but not endin $script:chocolatey_webpi_was_called.should.be($false) } + It "should not call Chocolatey-WindowsFeatures" { + $script:chocolatey_windowsfeatures_was_called.should.be($false) + } + It "should not call Chocolatey-RubyGem" { $script:chocolatey_rubygem_was_called.should.be($false) } @@ -101,6 +109,10 @@ Describe "When calling Chocolatey-Install from a manifest named packages.config" $script:chocolatey_webpi_was_called.should.be($false) } + It "should not call Chocolatey-WindowsFeatures" { + $script:chocolatey_windowsfeatures_was_called.should.be($false) + } + It "should not call Chocolatey-RubyGem" { $script:chocolatey_rubygem_was_called.should.be($false) } @@ -124,6 +136,10 @@ Describe "When calling Chocolatey-Install from a manifest named MyChocolateyPack $script:chocolatey_webpi_was_called.should.be($false) } + It "should not call Chocolatey-WindowsFeatures" { + $script:chocolatey_windowsfeatures_was_called.should.be($false) + } + It "should not call Chocolatey-RubyGem" { $script:chocolatey_rubygem_was_called.should.be($false) } @@ -147,6 +163,10 @@ Describe "When calling Chocolatey-Install with ruby as the source" { $script:chocolatey_webpi_was_called.should.be($false) } + It "should not call Chocolatey-WindowsFeatures" { + $script:chocolatey_windowsfeatures_was_called.should.be($false) + } + It "should call Chocolatey-RubyGem" { $script:chocolatey_rubygem_was_called.should.be($true) } @@ -162,7 +182,7 @@ Describe "When calling Chocolatey-Install with webpi as the source" { Chocolatey-Install "dude" -source 'webpi' - It "should not call Chocolatey-PackagesConfig" { + It "should not call Chocolatey-PackagesConfig" { $script:chocolatey_packagesconfig_was_called.should.be($false) } @@ -170,6 +190,37 @@ Describe "When calling Chocolatey-Install with webpi as the source" { $script:chocolatey_webpi_was_called.should.be($true) } + It "should not call Chocolatey-WindowsFeatures" { + $script:chocolatey_windowsfeatures_was_called.should.be($false) + } + + It "should not call Chocolatey-RubyGem" { + $script:chocolatey_rubygem_was_called.should.be($false) + } + + It "should not call Chocolatey-NuGet" { + $script:chocolatey_nuget_was_called.should.be($false) + } +} + +Describe "When calling Chocolatey-Install with windowsfeatures as the source" { + Initialize-Variables + $script:exec_chocolatey_install_actual = $true + + Chocolatey-Install "dude" -source 'windowsfeatures' + + It "should not call Chocolatey-PackagesConfig" { + $script:chocolatey_packagesconfig_was_called.should.be($false) + } + + It "should not call Chocolatey-WebPI" { + $script:chocolatey_webpi_was_called.should.be($false) + } + + It "should call Chocolatey-WindowsFeatures" { + $script:chocolatey_windowsfeatures_was_called.should.be($true) + } + It "should not call Chocolatey-RubyGem" { $script:chocolatey_rubygem_was_called.should.be($false) } diff --git a/tests/unit/Chocolatey-PackagesConfig.tests.ps1 b/tests/unit/Chocolatey-PackagesConfig.tests.ps1 index 0f9862c..6409eea 100644 --- a/tests/unit/Chocolatey-PackagesConfig.tests.ps1 +++ b/tests/unit/Chocolatey-PackagesConfig.tests.ps1 @@ -284,4 +284,33 @@ Describe "When calling Chocolatey-PackagesConfig with a packages.config manifest $script:chocolatey_nuget_was_called.should.be($false) } +} + +Describe "When calling Chocolatey-PackagesConfig with a packages.config manifest that has windowsfeatures packages" { + Initialize-Variables + $script:exec_chocolatey_packagesconfig_actual = $true + + Setup -File 'packages.config' @" + + + + +"@ + + Chocolatey-PackagesConfig "TestDrive:\packages.config" + + It "should execute the contents of the packages.config" {} + + It "should call Chocolatey-Install" { + $script:chocolatey_install_was_called.should.be($true) + } + + It "should set the source to windowsfeatures" { + $script:source.should.be('windowsfeatures') + } + + It "should not call Chocolatey-Nuget" { + $script:chocolatey_nuget_was_called.should.be($false) + } + } \ No newline at end of file