Skip to content
This repository was archived by the owner on Feb 19, 2019. It is now read-only.

Commit

Permalink
Add the Windows Feature list as a Chocolatey feed
Browse files Browse the repository at this point in the history
  • Loading branch information
mwrock committed Sep 10, 2012
1 parent 91447d6 commit 9f88317
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 3 deletions.
6 changes: 6 additions & 0 deletions nuget/tools/chocolateysetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
$nugetChocolateyWinFeaturesAlias = Join-Path $chocolateyExePath 'cwinfeatures.bat'
$nugetChocolateyCygwinAlias = Join-Path $chocolateyExePath 'ccygwin.bat'
$nugetChocolateyPythonAlias = Join-Path $chocolateyExePath 'cpython.bat'
$nugetChocolateyGemAlias = Join-Path $chocolateyExePath 'cgem.bat'
Expand Down Expand Up @@ -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 `'$nugetChocolateyWinFeaturesAlias`' 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%
Expand Down
1 change: 1 addition & 0 deletions src/chocolatey.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
4 changes: 2 additions & 2 deletions src/functions/Chocolatey-Help.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/functions/Chocolatey-Install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
3 changes: 3 additions & 0 deletions src/functions/Chocolatey-List.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ param(
if ($source -like 'webpi') {
$webpiArgs ="/c webpicmd /List /ListOption:All"
& cmd.exe $webpiArgs
} elseif ($source -like 'windowsfeatures') {
$windowsFeaturesArgs ="/c dism /online /get-features /format:table"
& cmd.exe $windowsFeaturesArgs
} else {

$srcArgs = Get-SourceArguments $source
Expand Down
33 changes: 33 additions & 0 deletions src/functions/Chocolatey-WindowsFeatures.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function Chocolatey-WindowsFeatures {
param(
[string] $packageName
)
Write-Debug "Running 'Chocolatey-WindowsFeatures' for $packageName with installerArguments:`'$installerArguments`'";

@"
$h1
Chocolatey ($chocVer) is installing `'$packageName`' (from Windows Veatures)..
$h1
"@ | Write-Host

$chocoInstallLog = Join-Path $nugetChocolateyPath 'chocolateyWindowsFeaturesInstall.log';
Remove-LastInstallLog $chocoInstallLog

$packageArgs = "/c DISM /Online /NoRestart /Enable-Feature /all /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

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
}
1 change: 1 addition & 0 deletions tests/_FunctionRenameActuals.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/_Initialize-Variables.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = ''
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/_Setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
9 changes: 9 additions & 0 deletions tests/functions/Chocolatey-WindowsFeatures.ps1
Original file line number Diff line number Diff line change
@@ -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}
}
53 changes: 52 additions & 1 deletion tests/unit/Chocolatey-Install.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -162,14 +182,45 @@ 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)
}

It "should call Chocolatey-WebPI" {
$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)
}
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/Chocolatey-PackagesConfig.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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' @"
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="chocolateytestpackage" source="windowsfeatures" />
</packages>
"@

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)
}

}

0 comments on commit 9f88317

Please sign in to comment.